writing-java-tests
Installation
SKILL.md
Writing Test
Use this skill to choose the right test level first, then write compact contract-focused Java tests.
Use JUnit APIs for assertions and test structure. Mockito is allowed when interaction matters, but keep assertions in JUnit. Do not introduce AssertJ, Hamcrest, Truth, or other assertion libraries unless the project already uses them. For E2E JSON body checks, use jsonPath; Hamcrest matchers are allowed only inside jsonPath assertions.
Workflow
- Read the target code and nearby tests before writing anything.
- Decide the lowest useful test level: unit, integration, or E2E.
- Load the matching reference only when needed:
- Unit tests: references/unit.md
- Integration tests: references/integration.md
- E2E tests: references/e2e.md
- Identify the public contract and add the smallest useful test set.
- Avoid duplicate coverage across levels.
- Put unit and integration tests in the module that owns the behavior.
- Run the narrowest relevant test command first, then broader tests when risk justifies it.