/testing-automation:java-junitfrom testing-automation
Guides JUnit 5 test implementation with best practices for project setup, test structure, parameterized tests, Mockito mocking, and build-tool commands. Useful when writing or reviewing Java unit tests.
Ships in testing-automation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guide Java test implementation by turning behavior requirements into focused JUnit 5 tests that use idiomatic project structure, per-test lifecycle hooks, data-driven parameterized data, assertions, mocking, human-readable organization, and build-tool validation.
@ParameterizedTest."| Concern | Rule |
|---|---|
| Structure | Use standard Maven or Gradle layout; put tests in src/test/java. |
| Dependencies | Include junit-jupiter-api, junit-jupiter-engine, and junit-jupiter-params for parameterized tests. |
| Commands | Run mvn test or gradle test; narrow with build-tool filters when needed. |
| Class names | Use a Test suffix, for example CalculatorTest for Calculator. |
| Feature | Use | Notes |
|---|---|---|
@Test | Standard test methods. | One behavior per test. |
| Arrange-Act-Assert | Test body shape. | Keep setup, action, and verification clear. |
methodName_should_expectedBehavior_when_scenario | Descriptive naming. | Match existing project style if stronger. |
@BeforeEach / @AfterEach | Per-test setup and teardown. | Reset mutable state. |
@BeforeAll / @AfterAll | Per-class setup and teardown. | Static by default unless using a per-class lifecycle. |
@DisplayName | Human-readable class or method names. | Useful for business-readable scenarios. |
@Nested | Group related scenarios. | Keeps context-specific setup close to tests. |
| Source | Use it for | Notes |
|---|---|---|
@ParameterizedTest | Any test run with multiple input rows. | Pair with exactly one source. |
@ValueSource | Simple literal strings, ints, longs, doubles, classes, or booleans. | Best for one-parameter tests. |
@MethodSource | Factory method returning Stream, Collection, iterable, or arguments. | Best for computed or named cases. |
@CsvSource | Small inline comma-separated rows. | Keep rows readable. |
@CsvFileSource | CSV file from the classpath. | Use for larger stable datasets. |
@EnumSource | Enum constants. | Filter modes are useful for subsets. |
| Need | Assertion |
|---|---|
| Equality | assertEquals(expected, actual); baseline form assertEquals. |
| Truthiness | assertTrue, assertFalse. |
| Nullability | assertNotNull, assertNull. |
| Exception path | assertThrows. |
| No exception path | assertDoesNotThrow. |
| Multiple related checks | assertAll so all assertions run before failure. |
| Fluent style | AssertJ assertThat(...).is... only if the project already uses or accepts AssertJ. |
Import static methods from org.junit.jupiter.api.Assertions. Add descriptive messages when they make failure diagnostics clearer.
| Technique | Use when | Avoid |
|---|---|---|
| Mockito | Collaborators need isolation. | Mocking value objects or the class under test. |
@Mock | Declare mock dependencies. | Manual mock setup repeated across tests. |
@InjectMocks | Construct class under test from mocks. | Hiding complex construction that should be explicit. |
| Interfaces | Facilitate mocking and substitutions. | Introducing interfaces solely for trivial classes. |
| Packages | Group tests by feature or component. | Dumping all tests into one utility package. |
@Tag("fast"), @Tag("integration") | Categorize suites; baseline shorthand @Tag. | Using tags to hide slow tests instead of fixing scope. |
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order | Only when order is strictly necessary. | Routine unit tests; independence is preferred. |
@Disabled | Temporary skip with a reason. | Permanent silent skips. |
@TestMethodOrder only for rare ordered workflows, not normal unit tests.@SpringBootTest for ordinary unit tests: prefer plain JUnit and Mockito unless a Spring context is required.@Disabled: include a reason and track follow-up work.## JUnit 5 test plan
**Target:** `<class or behavior>`
**Command:** `mvn test` or `gradle test`
| Test | Annotation | Data source | Behavior verified |
| --- | --- | --- | --- |
| `<methodName_should_expectedBehavior_when_scenario>` | `@Test` or `@ParameterizedTest` | `<none / ValueSource / MethodSource / CsvSource / CsvFileSource / EnumSource>` | `<single behavior>` |
### Notes
- Lifecycle: `<BeforeEach/AfterEach/BeforeAll/AfterAll or none>`
- Assertions: `<Assertions or AssertJ>`
- Isolation: `<Mockito mocks or real collaborators>`
src/test/java and run with mvn test or gradle test.junit-jupiter-api, junit-jupiter-engine, and junit-jupiter-params when parameterized tests are used.@Test or @ParameterizedTest appropriately and follow Arrange-Act-Assert.assertThrows or assertDoesNotThrow where relevant.@Nested are used only when they clarify the test suite.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
junit5, unit-testing, java-testing, mockito, parameterized-tests
13 skills in this plugin
/ai-prompt-engineering-safety-reviewReview and improve AI prompts for safety, bias, security, privacy, effectiveness, robustness, and testability. Use this skill when the user asks to audit a prompt, harden a system prompt, identify prompt injection risk, reduce bias, improve guardrails, or produce a safer enhanced prompt./csharp-nunitDesign, write, and review NUnit tests for .NET projects, including standard tests, data-driven tests, assertions, setup/teardown, categories, and isolation with mocks. Use this skill when the user asks for NUnit best practices, `dotnet test`, `[TestCase]`, `[TestCaseSource]`, or C# unit test structure./javascript-typescript-jestWrite and review JavaScript and TypeScript Jest tests with strong structure, mocks, async handling, snapshots, and React Testing Library patterns. Use this skill when the user asks to add Jest tests, improve test structure, mock APIs or databases, test async code, update snapshots, or test React components./pester-migrationUpgrade PowerShell Pester test suites across major versions v3 to v4, v4 to v5, and v5 to v6 while preserving test intent. Use when asked to migrate, modernize, or fix *.Tests.ps1 files after a Pester version bump, convert legacy Should or Invoke-Pester syntax, handle Discovery/Run failures, move setup into BeforeAll, migrate mocks, or adopt PesterConfiguration./pester-should-migrationConvert classic Pester v5 `Should -...` assertions to Pester v6 `Should-*` assertion commands while preserving behavior. Use when asked to migrate, convert, rewrite, or modernize `Should -Be`, `Should -Not -Be`, `Should -Throw`, `Should -Invoke`, or other assertions in .Tests.ps1 and PowerShell files./playwright-automation-fill-in-formAutomate filling and reviewing a Microsoft Forms response with Playwright MCP. Use this skill when the user asks to open a form, fill specific fields, upload an image, or prepare but not submit a Playwright-driven form response.npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin testing-automationOther plugins' skills for the same job