131-java-testing-unit-testing
提供实践示例与迁移建议,适合提升测试质量
审查、改进或编写现代 Java 单元测试(JUnit5、AssertJ、Mockito)
写或改单元测试时提供实操建议:从 JUnit4 迁移到 JUnit5、用 AssertJ 写流式断言、用 Mockito Mock 依赖。适合需要让测试更快、更独立、加参数化用例或消除反模式(反射测试、共享可变状态)时用。强调 Given‑When‑Then 结构、清晰命名和边界条件覆盖,提升可读性与可靠性。
▸ 展开 SKILL.md 英文原文
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; Write fast JUnit unit tests for Java code; Improve Mockito-based Java unit tests; Refactor Java tests to isolate collaborators. Part of Plinth Toolkit
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/131-java-testing-unit-testing/SKILL.mdcurl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/131-java-testing-unit-testing/SKILL.md"# 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: refle