Review and improve Java unit tests using modern JUnit 5, AssertJ, and Mockito best practices.
Prerequisites: Run ./mvnw compile or mvn compile before applying any change. If compilation fails, stop immediately and do not proceed — compilation failure is a blocking condition.
Core areas: 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 with @ValueSource/@CsvSource/@MethodSource, Mockito dependency mocking (@Mock, @InjectMocks, MockitoExte...
当您需要审查、改进或编写 Java 单元测试时使用 - 包括从 JUnit 4 迁移到 JUnit 5、采用 AssertJ 进行流畅断言、使用 Give-When-Then 构建测试、确保测试独立性、应用参数化测试、使用 Mockito 模拟依赖关系、验证边界条件(RIGHT-BICEP、CORRECT、A-TRIP)、利用 JSpecify 空安全注释或消除测试反模式(例如基于反射)测试或共享可变状态。 java 技能项目的一部分 来源:jabrena/cursor-rules-java。