Generate high-quality unit tests from test cases. Applies proven testing principles like Given-When-Then structure, focused tests, clean test data, and behavior-driven testing. Supports multiple languages with specialized rules for Java.
Resources
1Install
npx skillscat add clear-solutions/unit-tests-skills/generate-tests Install via the SkillsCat registry.
Generate Tests Skill
You will create automated tests for a given method and its test cases.
⚠️ MANDATORY PREREQUISITE
STOP! Before generating any test code, you MUST first run /generate-test-cases.
This is NOT optional. The two-step process is REQUIRED:
- FIRST: Run
/generate-test-cases <target>- outputs the list of test cases - THEN: Run
/generate-tests <target>- generates actual test code
Why this matters:
- Test cases ensure proper coverage based on INCLUDE/EXCLUDE rules
- Prevents missing edge cases and error scenarios
- Ensures consistent naming following conventions
- Allows review of test strategy before writing code
If test cases were NOT generated first:
You MUST invoke /generate-test-cases NOW before proceeding. Do NOT skip this step.
Rules Reference
CRITICAL: You MUST read and apply all relevant rules from the ./rules/tests/ directory:
General Rules (Always Apply)
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 methods
Java Unit Tests
java/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
Post-Generation
post-generation/compilation-verification.md- Verify compilation
Instructions
When this command is invoked, generate tests for the specified target:
Target to test: $ARGUMENTS
Steps:
- VERIFY test cases exist - If
/generate-test-caseswas NOT run, STOP and run it first - Read the relevant rules from
./rules/tests/based on code type - Read the source file/class/method specified above
- Analyze the code to determine the type (controller, service, repository, messaging, etc.)
- Apply the appropriate rules from the rules directory
- Generate comprehensive tests following all rules and the test cases list
- Create the test file(s) in the correct location using the Write tool
- Run compilation and fix any issues until tests compile successfully