npx skills add ...
npx skills add mavka-ai/unit-tests-skills --skill generate-tests
Use when the user asks to generate, create, write, or add unit tests for existing code, or to cover a class, method, or file with tests — including Java targets using JUnit 5, Mockito, or AssertJ. Not for analysis-only requests that stop at listing test cases.
npx skills add mavka-ai/unit-tests-skills --skill generate-tests
You will analyze code and generate high-quality unit tests for a given target.
Target to test: $ARGUMENTS
./rules/tests/ based on code type (see Rules Reference below)code-context-analysis rule){ClassName}Test or {ClassName}Tests in the test directory (as specified in existing-test-awareness rule)
If a test case list for this target is already present — generate-test-cases ran
first, whether the user invoked it or the agent did — that list is the plan. Generate
from it. Do not re-analyze the target from scratch; where your reading of the code
differs, name the cases you add or drop and why, so the change to the plan is visible.
If there is no such list, produce one here before writing any test code:
Either way, continue straight to Step 3. The list is printed so the user can audit the plan against the generated tests afterwards; the run stays unattended end to end.
Test method name format: {testedMethod}_{givenState}_{expectedOutcome}
Examples:
calculateTotal_validProducts_returnsSumcalculateTotal_emptyList_throwsIllegalArgumentExceptiongetUser_unauthorized_returns401controller-test-rules.md (use @WebMvcTest, MockMvc patterns)domain-service-rules.md (use @ExtendWith(MockitoExtension.class), Mockito patterns)domain-service-rules.md as baseline; inform the user that type-specific rules are not yet availablejava-test-template.md, argument-matching.md, json-serialization.md regardless of code typecompilation-verification.md)test-execution-verification.md)@Disabled
with the reason and report it (see test-execution-verification.md)If the specified target does not exist, inform the user with the exact path you searched and ask for clarification.
If the target code is in a language without specific rules (not Java), apply only the general rules and inform the user that language-specific conventions may need manual review.
If compilation fails after 5 attempts:
If tests fail because the production code behaves differently than expected:
// NOTE: current behavior may be a bug — {description}CRITICAL: You MUST read and apply all relevant rules from the ./rules/tests/ directory.
Maintenance note: General rules in
./rules/tests/general/are shared with thegenerate-test-casesskill (which has copies inrules/general/). When updating rules, keep both locations in sync.
general/test-case-generation-strategy.md - INCLUDE/EXCLUDE criteriageneral/naming-conventions.md - Test naming formatgeneral/general-principles.md - Core testing principles (Given-When-Then, actual/expected)general/technology-stack-detection.md - Detect language and frameworkgeneral/what-makes-good-test.md - Clarity, Completeness, Conciseness, Resiliencegeneral/cleanly-create-test-data.md - Use helpers and builders for test datageneral/keep-cause-effect-clear.md - Effects follow causes immediatelygeneral/no-logic-in-tests.md - KISS > DRY, avoid logic in assertionsgeneral/keep-tests-focused.md - One scenario per testgeneral/test-behaviors-not-methods.md - Separate tests for behaviorsgeneral/verify-relevant-arguments-only.md - Only verify relevant mock argumentsgeneral/prefer-public-apis.md - Test public APIs over private methodsgeneral/existing-test-awareness.md - Check for existing tests, match project conventionsgeneral/code-context-analysis.md - Read dependencies before writing testsjava/unit/java-test-template.md - Basic template, FORBIDDEN annotationsjava/unit/json-serialization.md - Use explicit JSON literalsjava/unit/argument-matching.md - Use ArgumentCaptor, not any()java/unit/logging-rules.md - OutputCaptureExtension for logsjava/unit/domain-service-rules.md - Mockito patterns for servicesjava/unit/controller-test-rules.md - @WebMvcTest and MockMvc patterns for controllerspost-generation/compilation-verification.md - Verify compilationpost-generation/test-execution-verification.md - Verify tests passUser says: "/generate-tests src/main/java/com/example/service/OrderService.java"
Step 1: Agent reads rules, reads OrderService.java, reads OrderRequest.java,
Order.java, OrderRepository.java (dependencies), checks for
existing OrderServiceTest.java
Step 2: Agent outputs 7 test cases covering:
- createOrder success path
- createOrder with invalid request (validation)
- processPayment success
- processPayment failure
- calculateTotal with products
- calculateTotal with empty list
- cancelOrder for non-existent order
Step 3: Agent generates OrderServiceTest.java with @ExtendWith(MockitoExtension.class),
mocked repository and payment service, 7 test methods.
Step 4: Agent runs `mvn test -Dtest=OrderServiceTest -q`, all tests pass.
Result: Complete test file delivered with 7 passing tests.