Java Testing Standards
**Priority: P0 (CRITICAL)**
Universal anti-slop rules (identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps, shallow
assertions, coverage): anti-slop-rules.md. Only Java deltas follow.
Stack Deltas
- JUnit 5 (Jupiter):
@Test,@BeforeEach,@AfterEach; avoid JUnit 4 classes. - AssertJ:
assertThat(...)over JUnitassertEquals; chain (isNotNull().hasSize(2).contains("X"));
assertThatThrownBy(() -> ...) for exception type and message.
- Naming:
MethodName_State_Resultor@DisplayName("Check if X when Y"). - Parameterized (
[BE-TEST-01]):@ParameterizedTestwith@ValueSource,@CsvSource, or@MethodSourcefor
equivalent inputs and boundary permutations; distinct scenarios or diverging setup may stay separate methods.
- Mockito (
[BE-TEST-04]):@ExtendWith(MockitoExtension.class),@Mock,@Spy,@InjectMocks; never mock
data-only records; assert observable contract outcomes, not call counts or invocation sequences.
- Integration (
[BE-TEST-02]):Testcontainerswith@Containerfor real PostgreSQL/Redis in*IT.java; no raw SQL
string mocks.
- Isolation: each method independent; use
@DirtiesContextsparingly. - Coverage: diagnostic and project-configured; verify risk-weighted critical paths.
Anti-Patterns
- No logic in tests: keep tests declarative; no loops or if/else branching.
- No
System.out: assert; never print. - No legacy assertions:
assertTrue(a == b)→assertThat(a).isEqualTo(b). - No shared state: tests must be isolated and order-independent.
- No padded tests: never add cases for an arbitrary coverage percentage.