
Java Junit
- 4 installs
- 7 repo stars
- Updated August 2, 2026
- practicalswan/agent-skills
java-junit is a Claude Code skill for ai & agent building.
About
Provides JUnit 5 conventions and parameterized-test patterns for Java code. A Java developer uses it when writing or reviewing unit tests.
- JUnit 5 testing patterns
- Parameterized-test guidance
Java Junit by the numbers
- 4 all-time installs (skills.sh)
- Ranked #1,631 of 2,153 Testing & QA skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/practicalswan/agent-skills --skill java-junitAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 4 |
|---|---|
| repo stars | ★ 7 |
| Last updated | August 2, 2026 |
| Repository | practicalswan/agent-skills ↗ |
How do I helps with ai & agent building tasks.?
JUnit 5 testing patterns and parameterized-test guidance for writing or reviewing Java unit tests.
Who is it for?
A solo builder working on ai & agent building tasks who needs structured help with java junit.
Skip if: Teams with no ai & agent building needs, or anyone wanting a generic chat assistant without this specific workflow.
When should I use this skill?
When you need to helps with ai & agent building tasks., or when java-junit is a claude code skill for ai & agent building.
What you get
Structured output aligned to java-junit: java-junit, AI & Agent Building.
Files
JUnit 5+ Best Practices
Optimized for current Java LTS releases, JUnit 5.x, Mockito 5.x, and modern Maven or Gradle builds.
Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches.
- Leverage native parallel subagent dispatch and 200k+ context windows where available.
Anti-Patterns
- Combining multiple behaviors in one test: A single failure should map cleanly to one broken contract.
- Using sleeps for asynchronous behavior: Time-based tests stay flaky even when the implementation is correct.
- Testing implementation details instead of behavior: Refactors become noisy because the tests are coupled to internals.
Verification Protocol
Before claiming "skill applied successfully":
1. Pass/fail: The Java Junit implementation names the target runtime, framework version, and affected files. 2. Pass/fail: Build, lint, test, or equivalent local validation is run for the changed surface. 3. Pass/fail: Edge cases for errors, dependency drift, and environment differences are addressed or explicitly out of scope. 4. Pressure-test scenario: Apply the workflow to a change that passes happy-path tests but fails one boundary condition. 5. Success metric: Zero untested success claims; every implementation claim maps to a command or artifact.
Before and After Example
// Before
@Test
void shouldWork() {
assertTrue(service.create(user));
}
// After
@Test
void create_WhenEmailAlreadyExists_ThrowsConflictException() {
// Arrange
repository.save(existingUser);
// Act + Assert
assertThrows(ConflictException.class, () -> service.create(duplicateUser));
}Shifts from a vague happy-path assertion to a precise behavioral test that captures the contract.
Project Setup
- Use a standard Maven or Gradle project structure.
- Place test source code in
src/test/java. - Include dependencies for
junit-jupiter-api,junit-jupiter-engine, andjunit-jupiter-paramsfor parameterized tests. - Use build tool commands to run tests:
mvn testorgradle test.
Test Structure
- Test classes should have a
Testsuffix, e.g.,CalculatorTestfor aCalculatorclass. - Use
@Testfor test methods. - Follow the Arrange-Act-Assert (AAA) pattern.
- Name tests using a descriptive convention, like
methodName_should_expectedBehavior_when_scenario. - Use
@BeforeEachand@AfterEachfor per-test setup and teardown. - Use
@BeforeAlland@AfterAllfor per-class setup and teardown (must be static methods). - Use
@DisplayNameto provide a human-readable name for test classes and methods.
Standard Tests
- Keep tests focused on a single behavior.
- Avoid testing multiple conditions in one test method.
- Make tests independent and idempotent (can run in any order).
- Avoid test interdependencies.
Data-Driven (Parameterized) Tests
- Use
@ParameterizedTestto mark a method as a parameterized test. - Use
@ValueSourcefor simple literal values (strings, ints, etc.). - Use
@MethodSourceto refer to a factory method that provides test arguments as aStream,Collection, etc. - Use
@CsvSourcefor inline comma-separated values. - Use
@CsvFileSourceto use a CSV file from the classpath. - Use
@EnumSourceto use enum constants.
Assertions
- Use the static methods from
org.junit.jupiter.api.Assertions(e.g.,assertEquals,assertTrue,assertNotNull). - For more fluent and readable assertions, consider using a library like AssertJ (
assertThat(...).is...). - Use
assertThrowsorassertDoesNotThrowto test for exceptions. - Group related assertions with
assertAllto ensure all assertions are checked before the test fails. - Use descriptive messages in assertions to provide clarity on failure.
Mocking and Isolation
- Use a mocking framework like Mockito to create mock objects for dependencies.
- Use
@Mockand@InjectMocksannotations from Mockito to simplify mock creation and injection. - Use interfaces to facilitate mocking.
Test Organization
- Group tests by feature or component using packages.
- Use
@Tagto categorize tests (e.g.,@Tag("fast"),@Tag("integration")). - Use
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)and@Orderto control test execution order when strictly necessary. - Use
@Disabledto temporarily skip a test method or class, providing a reason. - Use
@Nestedto group tests in a nested inner class for better organization and structure.
Common Pitfalls
- Combining multiple behaviors in one test: Failures become ambiguous and the test no longer documents a single contract.
- Using sleeps instead of deterministic setup: Time-based tests stay flaky even when the production code is correct.
- Asserting only that no exception occurred: A test without a meaningful assertion cannot prove the behavior is right.
<!-- PORTABILITY:START -->
Cross-Client Portability
This skill is written to stay usable across GitHub Copilot, Claude Code, Codex, and Gemini CLI.
- GitHub Copilot: keep the folder in a Copilot-visible skill or plugin path, or wrap the workflow as project instructions if the host does not support portable skill folders directly.
- Claude Code: keep the folder in a local skills directory or a compatible plugin or marketplace source.
- Codex: install or sync the folder into
$CODEX_HOME/skills/<skill-name>and restart Codex after major changes. - Gemini CLI: this repository generates a project command named
/skills:java-junitfrom this skill. Rebuild commands withpython scripts/export-gemini-skill.py java-junitand then run/commands reloadinside Gemini CLI.
<!-- PORTABILITY:END -->
<!-- MCP:START -->
MCP Availability And Fallback
Preferred MCP Server: None required
- Fallback prompt: "Use the JUnit 5+ Best Practices skill without MCP. Rely on the local
SKILL.md, bundled references or scripts, and manual verification. Show the exact commands, evidence, and final checks you used before concluding." - If the current host does not expose a matching server, use the bundled references, scripts, native toolchain, and manual workflow already described in this skill.
- Treat direct local verification, rendered output, logs, tests, or screenshots as the fallback evidence path before completion.
<!-- MCP:END -->
Related Skills
- java-docs: Use it when the workflow also needs Java API and JavaDoc documentation guidance.
- test-driven-development: Use it when the workflow also needs test-first implementation and regression safety.
- code-quality: Use it when the workflow also needs two-stage review (spec compliance first, then code quality), maintainability, and refactoring guidance.
- systematic-debugging: Use it when the workflow also needs root-cause debugging before proposing fixes.
Changelog
[2026-04-25] - Version 1.2 Verification Protocol Refresh
Added
- Added a
Verification Protocolsection with skill-specific pass/fail checks, one pressure-test scenario, and a measurable success metric. - Added guidance to leverage native parallel subagent dispatch and 200k+ context windows where available.
Changed
- Updated
SKILL.mdfrontmatter toversion: "1.2"andlast_updated: 2026-04-25. - Reframed activation guidance toward symptom -> action triggers and standardized two-stage review wording where applicable.
[2026-04-24] - Version 1.1 Refresh
Changed
- Updated the SKILL frontmatter version to
1.1for the 2026-04-24 catalog refresh. - Added an "Optimized for ..." note at the top so the guidance is anchored to current platform versions.
All notable changes to the java-junit skill will be documented in this file.
[2026-04-24] - Skill Refresh
Changed
- Standardized the SKILL frontmatter with version metadata, last-updated date, tags, and a concise catalog description.
- Reformatted the portability and MCP guidance with a preferred server line, a copy-paste fallback prompt, and consistent bullet lists.
- Added a catalog-standard Anti-Patterns section and refreshed the Related Skills links at the end of the skill.
- Added an explicit before-and-after example and a Common Pitfalls section for modern JUnit usage.
[2026-04-04] - Initial Import and Portability Upgrade
Added
- Imported this skill from
https://github.com/github/awesome-copilotatskills/java-junit. - Added cross-client portability guidance for GitHub Copilot, Claude Code, Codex, and Gemini CLI.
- Added the repo-standard MCP or no-MCP fallback guidance for this skill.
Changed
- Rewrote the frontmatter description to match the activation-focused style used by the maintained catalog.
Tested
- Validated
SKILL.mdfrontmatter and Gemini command export readiness withpython scripts/validate-skills.py.
Related skills
FAQ
What does java-junit do?
java-junit is a Claude Code skill for ai & agent building.
When should I use java-junit?
When you need to helps with ai & agent building tasks., or when java-junit is a claude code skill for ai & agent building.
What are the main capabilities?
java-junit; AI & Agent Building; AI-coding skill.