Writing java tests
개인용 에이전트 스킬 모음집
npx -y skills add dungsil/skills --skill writing-java-testsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 28 days oldThe repository was created 28 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Write, improve, or review Java tests with JUnit, Mockito, Spring Boot, Spring Data JPA, and JSpecify across unit, integration, and E2E levels. Use only for Java test work, including domain, use-case, entity, validation, repository, adapter, HTTP API, nullability, or Java test-level selection decisions.
SKILL.md
5.7 KB, as published. Nobody here has run it
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.
Test Levels
Choose the lowest useful level:
- Domain value object, entity helper method, use-case branch, repository adapter call shape: unit test.
- JPA entity mapping, repository query method, transaction/lifecycle behavior: integration test.
- HTTP route, serialization, security filter, controller-service-use-case-repository flow: E2E test.
Avoid duplicate coverage:
- If E2E verifies HTTP -> repository -> domain -> JSON, do not also assert every mapped domain field in adapter unit tests.
- Keep adapter unit tests only for adapter-specific policy, such as forcing
activeOnly = trueon repository calls. - Keep entity unit tests for pure entity helper contracts such as
isDeleted()andsetDeleted().
Test Fixtures
- Use Gradle
java-test-fixturesonly when fixtures must be shared across modules. - Prefer fixtures in the adapter module that owns the fixture type.
- App-level E2E or integration tests may depend on
testFixtures(project(":<adapter-module>"))when they need adapter-owned entity fixtures. - Do not create a separate fixture module for a single adapter's test data.
Common Structure
Prefer @Nested groups when a class has multiple meaningful behavior surfaces.
If there is only one meaningful group, and the class is unlikely to expand soon, keep the test cases flat in the test class. Do not create a single @Nested group only for ceremony.
Within a group or flat class, place successful/valid cases first, then boundary cases, then invalid/exception cases.
Use @BeforeEach when multiple test cases repeat the same setup or fixture creation. Keep shared preconditions in setup and behavior-specific values inside the test method.
Naming
- Prefer
shouldBe...method names. - Use
shouldBeRejectedWhen...for invalid inputs. - Use
shouldBeReturned...When...for getter/helper return behavior. - Use
shouldBeThrownWhen...for expected exception paths. - Keep detailed behavior text in
@DisplayName; match the repository's language, but Korean test cases must always end with~해야 한다or~이어야 한다. - Always write E2E with uppercase
E2Ein class and file names, such asUserProfileE2ETest.
Assertions
Use assertAll when one action produces a state with multiple observable properties.
Avoid asserting exception messages unless the message is part of the public contract.
Gotchas
- Do not write null tests for non-null JSpecify contracts.
- Do not create controller unit tests only to mirror JSON response shape.
- Do not duplicate E2E coverage with repository or adapter tests unless the lower-level policy differs.
- Do not use AssertJ only because examples online use it; follow the project assertion stack.
- Do not verify JSON responses with raw string
contains; usejsonPathor parsed JSON assertions at the intended field path.
Nullability Policy
Respect JSpecify nullability contracts. Treat declared annotations as the source of truth.
- A parameter, field, or return type without
@Nullableis non-null under JSpecify defaults such as@NullMarked. Do not write tests that passnullto those parameters or expectnullfrom those returns. - A parameter, field, or return type with
@Nullablemay benull. Cover thenullcase explicitly, including the policy encoded by the production code. - If existing code is missing
@Nullablebut actually acceptsnull, fix the source annotation first, then write the test. - When verifying defensive behavior against a contract violation, suppress static checks with
@SuppressWarnings("DataFlowIssue")and make the intent clear in@DisplayName. - Annotate test helpers, fakes, and fixtures with JSpecify annotations to match the production contract. Do not relax nullability in test doubles.
Review Pass
Before finishing:
- Check the chosen test level is the lowest useful level.
- Check level-specific reference rules were followed.
- Check success cases appear before failure cases.
- Check method names follow project conventions.
- Check tests cover the intended contract without duplicating higher-level coverage.
- Check
nulltests exist only for declared nullable contracts or explicit misuse defense tests. - Check E2E class/file names use uppercase
E2E. - Check E2E JSON body assertions use
jsonPath. - Run the narrow test command and report the result.