Instruction file imported from ArulaAI/copilot-engineering-test-optimization-lab-java (
.github/instructions/test.instructions.md). Copyright stays with the author.
Naming
- Method format:
should[ExpectedBehavior]When[Condition]—shouldThrowWhenAmountIsNegative @ParameterizedTestmust includename = "..."with a readable sentence using{0},{1}placeholders
Assertions
- Use AssertJ (
assertThat()) exclusively — never JUnit'sassertEquals()orassertTrue() - For exceptions:
assertThatThrownBy(() -> ...)— nevertry/catchwithfail() - Assert on exception message and error code, not just exception type
- One assertion cluster per test — split if two unrelated things are asserted
Mocking
- BDD Mockito only:
given(...).willReturn(...)setup,then(...).should(...)verify — never mix withwhen/verify - Stub only what the test actually calls
- Verify only interactions that are the intent of the test — not incidental calls
Test Data
- Named constants for all boundary values — no magic numbers
- Use
@EnumSourcefor exhaustive enum coverage,@CsvSourcefor input/output pairs,@MethodSourcefor complex object scenarios
Time and Async
- Never call
LocalDate.now()orLocalDateTime.now()directly — injectClockand mock it - Never use
Thread.sleep()orMath.random()in tests - Use
CompletableFuture.join()with an explicit timeout — never.get()without one
Spring Context
- Service-layer tests use
@ExtendWith(MockitoExtension.class)— never@SpringBootTest