Use when you need to review, improve, or write Java unit tests — including migrating from JUnit 4 to JUnit 5, adopting AssertJ for fluent assertions, structuring tests with Given-When-Then, ensuring test independence, applying parameterized tests, mocking dependencies with Mockito, verifying boundary conditions (RIGHT-BICEP, CORRECT, A-TRIP), leveraging JSpecify null-safety annotations, or eliminating testing anti-patterns such as reflection-based tests or shared mutable state. This should trigger for requests such as Review Java code for unit tests; Apply best practices for unit tests in Java code. Part of cursor-rules-java project
88
85%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Review and improve Java unit tests using modern JUnit 5, AssertJ, and Mockito best practices.
What is covered in this Skill?
@Test, @BeforeEach, @AfterEach, @DisplayName, @Nested, @ParameterizedTestassertThat, assertThatThrownBy@ValueSource/@CsvSource/@MethodSource@Mock, @InjectMocks, MockitoExtensionassertThatThrownBy, exception messages@NullMarked, @NullableScope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
Before applying any unit test changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until resolved. After applying improvements, run full verification.
./mvnw compile or mvn compile before applying any change./mvnw clean verify or mvn clean verify after applying improvementsRun ./mvnw compile or mvn compile and stop immediately if compilation fails.
Read references/131-java-testing-unit-testing.md and identify modernization and quality gaps in current tests.
Implement or refactor tests using JUnit 5, AssertJ, Mockito, parameterization, and stronger boundary checks.
Run ./mvnw clean verify or mvn clean verify after applying improvements.
For detailed guidance, examples, and constraints, see references/131-java-testing-unit-testing.md.
762cb86
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.