Java JUnit
Write deterministic Java unit tests using the Jupiter and build conventions already present in the project.
npx skills add github/awesome-copilot@java-junit What it does
A test can pass on one workstation and fail when the time zone or test order changes. Java JUnit guides the agent through project conventions, controllable dependencies and assertions on visible behavior.
What changes after install
- Inspect existing build and test conventions first.
- Control time and randomness at a dependency boundary.
- Separate unit coverage from tests that need external services.
Install
Run this command with Node.js 22.20 or later and select your agent in the Skills CLI.
npx skills add github/awesome-copilot@java-junit Before using Java JUnit
- A Java project with a working Maven or Gradle test task and a compatible JDK.
Read the reviewed setup instructions for the selected workflow.
When to use it
- Cover a boundary case in a Java class.
- Refactor tests that depend on wall-clock time.
When not to use it
- Proving that a real database or message broker works by mocking its client.
A worked example
Give the agent a subscription that expires at a known instant. Ask for cases immediately before and at expiry, using the project’s existing assertion style. Where the production API accepts a clock, supply a fixed one so the boundary can be reproduced.
Troubleshooting
- If zero tests run, check the runner and discovery configuration.
- If a time-based case flakes, remove the wall clock from the fixture.
- If a mock assertion breaks after a refactor, check whether the interaction was actually part of the contract.
How it chooses an approach
Use parameterized cases when the same rule has several meaningful inputs. Use an integration test if correctness depends on the behavior of the real dependency.
When to use another skill
- Test-Driven Development for specifying a new behavior before coding.
- Systematic Debugging for tracing an intermittent failure.
- Verification Before Completion for checking the final test evidence.
What to check after it runs
Run the targeted test through the project’s normal build. Confirm the runner reports the expected case count and that changing the boundary condition would fail a case.
Related workflows
More in Testing
FAQ
- Does this require migrating the project to JUnit 6?
- Read the existing dependency and JDK configuration first. A major-version migration is a separate decision.
- Should every dependency be mocked?
- Use real simple values for ordinary business logic. Introduce a test double when the boundary matters to determinism or observation.