home / skills / partme-ai / full-stack-skills / junit
This skill helps you write and configure JUnit tests with annotations, assertions, and best practices for Java projects.
npx playbooks add skill partme-ai/full-stack-skills --skill junitReview the files below or copy the command above to add this skill to your agents.
---
name: junit
description: Provides comprehensive guidance for JUnit testing framework including test annotations, assertions, test lifecycle, and best practices. Use when the user asks about JUnit, needs to write Java unit tests, use JUnit annotations, or configure JUnit for Java projects.
license: Complete terms in LICENSE.txt
---
## When to use this skill
Use this skill whenever the user wants to:
- [待完善:根据具体工具添加使用场景]
## How to use this skill
[待完善:根据具体工具添加使用指南]
## Best Practices
[待完善:根据具体工具添加最佳实践]
## Keywords
[待完善:根据具体工具添加关键词]
This skill delivers practical, hands-on guidance for using the JUnit testing framework in Java projects. It covers core annotations, assertions, test lifecycle methods, parameterized tests, and integration tips for build tools and IDEs. The focus is on writing clear, maintainable unit tests and configuring JUnit for common project setups. Use it to quickly resolve testing questions or improve test quality.
The skill inspects common JUnit topics and provides targeted advice: which annotations to use (@Test, @BeforeEach, @AfterAll, @Nested, @Disabled), how assertions and assumptions work, and when to write parameterized or repeated tests. It explains lifecycle hooks, exception and timeout testing patterns, and best practices for test isolation and mocking. The guidance includes configuration notes for Maven, Gradle, and popular IDEs, plus troubleshooting tips for flaky tests.
Which JUnit version should I use?
Prefer JUnit 5 for new projects; it offers a richer extension model and clearer annotations. Use JUnit Vintage to run legacy JUnit 4 tests if needed.
How do I test exceptions in JUnit?
Use assertThrows to verify exceptions and capture the thrown instance for further assertions instead of try/catch idioms.
How to speed up slow tests?
Avoid external systems, use mocks or lightweight in-memory implementations, parallelize tests where safe, and minimize per-test expensive setup.