java-clean-testslisted
Install: claude install-skill CasLubbers/code-design-skills
# Clean tests in Java
Test code is production code. It is read more often than the code it covers, because it is read whenever the code breaks.
## Name the behaviour
The name is the failure report.
```java
// Bad
@Test void test1() { ... }
@Test void testWithdraw() { ... }
// Good
@Test void withdrawFailsWhenBalanceIsInsufficient() { ... }
@Test void withdrawLeavesBalanceUnchangedWhenItFails() { ... }
```
`@DisplayName` carries a full sentence where the method name gets unwieldy, and `@Nested` groups cases around one scenario.
## One concept per test
```java
// Bad — three unrelated assertions; the first failure hides the rest
@Test void testOrder() {
assertThat(order.total()).isEqualTo(euros(100));
assertThat(order.status()).isEqualTo(PENDING);
assertThat(order.items()).hasSize(3);
}
// Good — one reason to fail each
@Test void totalSumsItemPrices() { ... }
@Test void newOrderStartsPending() { ... }
```
Several assertions about *one* concept are fine — `assertThat(order).extracting(...)`, or `assertAll` when you want every field reported at once. The rule is one reason to fail, not one assertion statement.
## Arrange, act, assert
Three visible blocks, separated by a blank line. If arrange runs to twenty lines, the class under test needs too much to exist — that is a design signal, not a test problem.
```java
@Test
void withdrawFailsWhenBalanceIsInsufficient() {
var account = new Account(euros(50)); // arrange
var thrown