131-java-testing-unit-testing

Solid

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

Testing & QA 393 stars 78 forks Updated today Apache-2.0

Install

View on GitHub

Quality Score: 92/100

Stars 20%
86
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Java Unit testing guidelines Review and improve Java unit tests using modern JUnit 5, AssertJ, and Mockito best practices. **What is covered in this Skill?** - JUnit 5 annotations: `@Test`, `@BeforeEach`, `@AfterEach`, `@DisplayName`, `@Nested`, `@ParameterizedTest` - AssertJ fluent assertions: `assertThat`, `assertThatThrownBy` - Given-When-Then test structure, descriptive test naming, single-responsibility tests - Test independence and isolated state - Parameterized tests: `@ValueSource`/`@CsvSource`/`@MethodSource` - Mockito dependency mocking: `@Mock`, `@InjectMocks`, `MockitoExtension` - Code coverage guidance (JaCoCo), package-private test visibility - Testing anti-patterns: reflection, shared state, hard-coded values, testing implementation details - Error handling: `assertThatThrownBy`, exception messages - JSpecify null-safety: `@NullMarked`, `@Nullable` - RIGHT-BICEP coverage principles, A-TRIP test quality, CORRECT boundary condition verification **Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples. ## Constraints 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. - **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any change - **SAFETY**: If compilation fails, stop immediately and do not proceed — compilati...

Details

Author
jabrena
Repository
jabrena/cursor-rules-java
Created
1 years ago
Last Updated
today
Language
Java
License
Apache-2.0

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

Testing & QA Solid

130-java-testing-strategies

Use when you need to apply testing strategies for Java code — RIGHT-BICEP to guide test creation, A-TRIP for test quality characteristics, or CORRECT for verifying boundary conditions. This should trigger for requests such as Review Java code for testing strategies; Apply RIGHT-BICEP testing strategies in Java code; Apply A-TRIP testing strategies in Java code; Apply CORRECT boundary condition verification in Java code. Part of cursor-rules-java project

393 Updated today
jabrena
AI & Automation Listed

java-junit

JUnit 5 testing patterns and parameterized-test guidance. Use when writing or reviewing Java unit tests.

1 Updated today
bg-szy
Testing & QA Listed

java-testing

Trigger: Java tests, JUnit, Mockito, AssertJ, legacy code, characterization tests, seams. Generate and retrofit Java tests safely.

0 Updated 1 weeks ago
andresnator
Testing & QA Solid

321-frameworks-spring-boot-testing-unit-tests

Use when you need to write unit tests for Spring Boot applications — including pure unit tests with @ExtendWith(MockitoExtension.class) for @Service/@Component, slice tests with @WebMvcTest and @MockitoBean for controllers, @JsonTest for JSON serialization, parameterized tests with @CsvSource/@MethodSource, test profiles, and @TestConfiguration. For framework-agnostic Java use @131-java-testing-unit-testing. For integration tests use @322-frameworks-spring-boot-testing-integration-tests. Part of the skills-for-java project

393 Updated today
jabrena
Testing & QA Solid

132-java-testing-integration-testing

Use when you need to set up, review, or improve Java integration tests — including generating a BaseIntegrationTest.java with WireMock for HTTP stubs, detecting HTTP client infrastructure from import signals, injecting service coordinates dynamically via System.setProperty(), creating WireMock JSON mapping files with bodyFileName, isolating stubs per test method, verifying HTTP interactions, or eliminating anti-patterns such as Mockito-mocked HTTP clients or globally registered WireMock stubs. This should trigger for requests such as Review Java code for integration tests; Apply best practices for integration tests in Java code. Part of cursor-rules-java project

393 Updated today
jabrena