131-java-testing-unit-testing

仓库创建 2025年2月9日最近提交 3 天前SkillHot 收录 21 天前
▸ 精选理由

提供实践示例与迁移建议,适合提升测试质量

这个 Skill 做什么

审查、改进或编写现代 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

开发编程Java单元测试JUnit5Mockito通用
423
Stars
89
Forks
40
仓库内 Skill
+9
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/131-java-testing-unit-testing/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/131-java-testing-unit-testing/SKILL.md"
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
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有