Agent-skills-standard java-testing
Testing standards using JUnit 5, AssertJ, and Mockito for Java. Use when writing or reviewing Java unit tests, setting up parameterized tests, writing integration tests with Testcontainers, or working with Mockito mocks. (triggers: **/*Test.java, **/*IT.java, @Test, @ParameterizedTest, Mockito, AssertJ, assertThat, JUnit, Testcontainers)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/java/java-testing" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-java-testing && rm -rf "$T"
manifest:
skills/java/java-testing/SKILL.mdsource content
Java Testing Standards
Priority: P0 (CRITICAL)
Implementation Guidelines
- JUnit 5 (Jupiter): Use
,@Test
, and@BeforeEach
. Avoid JUnit 4 classes.@AfterEach - Fluent Assertions: Use
over JUnitAssertJ (assertThat)
— enhanced readability.assertEquals - Naming: Use
orMethodName_State_Result
.@DisplayName("Check if X when Y") - Parameterized Tests: Use
with@ParameterizedTest
,@ValueSource
, or@CsvSource
.@MethodSource - Mocking Strategy: Use
withMockito
(JUnit 5). Use@ExtendWith(MockitoExtension.class)
,@Mock
, and@Spy
. NEVER mock data-only Records.@InjectMocks - Integration Testing: Use
withTestcontainers
annotation for real databases (PostgreSQL/Redis) in integration tests (@Container
).*IT.java - Isolation: Each test method MUST isolated and independent; use
sparingly.@DirtiesContext - AssertJ Chaining: Chain assertions for clarity:
.assertThat(result).isNotNull().hasSize(2).contains("X") - Mocking verification: Use
to audit side-effects.verify(mock, times(1)).method() - Exceptions: Use
to verify specific Exception types and messages.assertThatThrownBy(() -> ...)
Anti-Patterns
- No Logic in Tests: Keep tests declarative; no loops or if/else branching.
- No System.out in Tests: Use assertions; never print to stdout.
- No Legacy Assertions: Use
, notassertThat(a).isEqualTo(b)
.assertTrue(a == b) - No Shared State: Tests must isolated and order-independent.