
Java Junit
Guide an agent through JUnit 5 unit and parameterized tests in Maven or Gradle Java projects.
Overview
java-junit is an agent skill for the Ship phase that guides JUnit 5 unit and parameterized test authoring in Maven or Gradle Java projects.
Install
npx skills add https://github.com/github/awesome-copilot --skill java-junitWhat is this skill?
- Covers Maven/Gradle layout with junit-jupiter-api, engine, and params dependencies
- Enforces Arrange-Act-Assert and methodName_should_expectedBehavior_when_scenario naming
- Documents @BeforeEach, @AfterEach, @BeforeAll, @AfterAll, and @DisplayName usage
- Parameterized tests with @ParameterizedTest, @ValueSource, and related sources
- Run via mvn test or gradle test from standard src/test/java structure
Adoption & trust: 10.1k installs on skills.sh; 34.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Java service lacks consistent JUnit 5 structure, naming, and parameterized cases, so agents produce flaky or outdated test patterns.
Who is it for?
Solo builders maintaining Spring or plain Java services who want agent-generated tests to match team JUnit 5 conventions.
Skip if: Teams still on JUnit 4 only, non-JVM stacks, or projects that need full integration or contract-test playbooks instead of unit scope.
When should I use this skill?
Get best practices for JUnit 5 unit testing, including data-driven tests
What do I get? / Deliverables
You get focused, independent tests with AAA layout, lifecycle hooks, display names, and data-driven methods runnable via mvn test or gradle test.
- JUnit 5 test classes with Test suffix and AAA structure
- Parameterized test methods where multiple inputs apply
Recommended Skills
Journey fit
How it compares
Use for procedural JUnit 5 guidance instead of asking the agent to invent test style from generic Java snippets.
Common Questions / FAQ
Who is java-junit for?
Indie and solo developers using Claude Code, Cursor, or Codex on Maven or Gradle Java codebases who want reliable unit-test scaffolding.
When should I use java-junit?
During Ship testing when adding or refactoring unit tests, especially before a release or when introducing parameterized cases for edge inputs.
Is java-junit safe to install?
It is documentation-style guidance without shell or network hooks in the skill itself; review the Security Audits panel on this Prism page before trusting any upstream repo.
SKILL.md
READMESKILL.md - Java Junit
# JUnit 5+ Best Practices Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches. ## 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`, and `junit-jupiter-params` for parameterized tests. - Use build tool commands to run tests: `mvn test` or `gradle test`. ## Test Structure - Test classes should have a `Test` suffix, e.g., `CalculatorTest` for a `Calculator` class. - Use `@Test` for test methods. - Follow the Arrange-Act-Assert (AAA) pattern. - Name tests using a descriptive convention, like `methodName_should_expectedBehavior_when_scenario`. - Use `@BeforeEach` and `@AfterEach` for per-test setup and teardown. - Use `@BeforeAll` and `@AfterAll` for per-class setup and teardown (must be static methods). - Use `@DisplayName` to 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 `@ParameterizedTest` to mark a method as a parameterized test. - Use `@ValueSource` for simple literal values (strings, ints, etc.). - Use `@MethodSource` to refer to a factory method that provides test arguments as a `Stream`, `Collection`, etc. - Use `@CsvSource` for inline comma-separated values. - Use `@CsvFileSource` to use a CSV file from the classpath. - Use `@EnumSource` to 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 `assertThrows` or `assertDoesNotThrow` to test for exceptions. - Group related assertions with `assertAll` to 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 `@Mock` and `@InjectMocks` annotations from Mockito to simplify mock creation and injection. - Use interfaces to facilitate mocking. ## Test Organization - Group tests by feature or component using packages. - Use `@Tag` to categorize tests (e.g., `@Tag("fast")`, `@Tag("integration")`). - Use `@TestMethodOrder(MethodOrderer.OrderAnnotation.class)` and `@Order` to control test execution order when strictly necessary. - Use `@Disabled` to temporarily skip a test method or class, providing a reason. - Use `@Nested` to group tests in a nested inner class for better organization and structure.