Skip to content

Commit

Permalink
chore: add small documentation skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Apr 11, 2023
1 parent c4cb00b commit 28ce76c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 59 deletions.
71 changes: 12 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,18 @@
![Lines of code](https://img.shields.io/tokei/lines/github/volodya-lombrozo/jtcop?branch=main&label=Lines-of-Code)
[![codecov](https://codecov.io/gh/volodya-lombrozo/jtcop/branch/main/graph/badge.svg)](https://codecov.io/gh/volodya-lombrozo/jtcop)

Almost each project uses unit tests in its codebase. It is important to have a
common pattern of naming all that tests, because otherwise the project and tests
itself become a complete mess. It's a quite large discussion about
different [test naming patterns](https://stackoverflow.com/questions/155436/unit-test-naming-best-practices)
.
**jtcop** maven plugin helps to keep following a single common
test naming rule across all of your test classes.

## Conventions

The only one convention that is supported by this plugin for now is the
**present tense without subject**.

### Present tense without subject

The test method name should be a sentence that describes the test case using
present tense without subject. For example, if you have a test that tests
a `User` class, then the test method name should start from the verb followed by
any testing conditions. For example:

```java
public class UserTest {
@Test
public void createsUser() {
// correct
}

@Test
public void createsUserWithoutName() {
// correct
}

@Test
public void removesUser() {
// correct
}
}
```

The next cases will be considered as invalid:

```java
public class UserTest {
@Test
public void createUser() {
// invalid!
}

@Test
public void userIsCreated() {
// invalid!
}

@Test
public void userIsRemoved() {
// invalid!
}
}
```
This repository was inspired by various articles and discussion threads (such as
these
ones: ["Unit test naming best practices"](https://stackoverflow.com/questions/155436/unit-test-naming-best-practices)
and ["On The Layout of Tests"](https://www.yegor256.com/2023/01/19/layout-of-tests.html)),
and it consolidates knowledge on
best practices for organizing and naming tests. The purpose of jtcop is to
enhance the clarity and maintainability of your tests. In other words, jtcop is
a static linter similar to tools
like [CheckStyle](https://checkstyle.sourceforge.io)
or [PMD](https://pmd.github.io), but with a focus on test best practices.

You can read more about checks and rules in the [docs](docs/README.md).

## How to use

Expand Down
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Documentation

This directory contains the documentation for the project.

## Rules

This directory contains the documentation for the rules.
- [Present Tense](rules/present-tense.md)
- [Camel Case](rules/camel-case.md)
42 changes: 42 additions & 0 deletions docs/rules/camel-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Camel Case

Each test name has to be written by using [camel case](https://en.wikipedia.org/wiki/Camel_case).

Correct examples:
```java
public class UserTest {
@Test
public void createsUser() {
// correct
}

@Test
public void createsUserWithoutName() {
// correct
}

@Test
public void removesUser() {
// correct
}
}
```
Incorrect examples:
```java
public class UserTest {
@Test
public void create_user() {
// invalid!
}

@Test
public void user_is_created() {
// invalid!
}

@Test
public void user$is$removed() {
// invalid!
}
}
```
46 changes: 46 additions & 0 deletions docs/rules/present-tense.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Present tense

The test method name should be a sentence that describes the test case using
present tense without subject. For example, if you have a test that tests
a `User` class, then the test method name should start from the verb followed by
any testing conditions. For example:

```java
public class UserTest {
@Test
public void createsUser() {
// correct
}

@Test
public void createsUserWithoutName() {
// correct
}

@Test
public void removesUser() {
// correct
}
}
```

The next cases will be considered as invalid:

```java
public class UserTest {
@Test
public void createUser() {
// invalid!
}

@Test
public void userIsCreated() {
// invalid!
}

@Test
public void userIsRemoved() {
// invalid!
}
}
```

0 comments on commit 28ce76c

Please sign in to comment.