| name | test |
| description | Generate comprehensive tests for code. Dispatches to qa-analyst agent for complex
components requiring test architecture decisions.
AUTOMATICALLY INVOKE when:
- "write tests", "test this", "generate tests", "add test coverage"
- "test plan", "what should I test"
- After feature implementation is complete
NOT for: Running existing tests (use `npm test`)
|
| argument-hint | [file-path or function-name] |
| allowed-tools | all |
/test — Test Generation
Generate tests for specified code. Detects the project's test framework automatically
and matches existing test patterns.
Step 0 — Parse Arguments
From the invocation args, extract:
- target: File path, function name, or component to test
- --framework: Override test framework detection (mocha, jest, vitest, pytest)
- --unit-only: Skip integration test generation
If no target specified, use recently modified files:
git diff --name-only HEAD~1
Step 1 — Detect Test Infrastructure
Scan the project for existing test setup:
- Check package.json for test scripts and dependencies (mocha, jest, vitest, chai)
- Find existing test files:
Glob("**/*.test.*") and Glob("**/*.spec.*")
- Read 1-2 existing test files to match style (imports, describe/it patterns, assertion style)
- Identify test directory convention (test/, tests/, co-located)
Step 2 — Triage
Fast path (inline generation):
- Single function or small file (< 100 lines)
- Clear inputs/outputs, no complex dependencies
- Proceed to Step 3a
Agent path (dispatch):
- Complex component with multiple methods
- Requires mocking strategy decisions
- Integration tests needed across modules
- Proceed to Step 3b
Step 3a — Inline Test Generation
- Read the target file completely
- Identify testable units: exported functions, public methods, API endpoints
- Generate tests matching the project's existing style:
- Happy path for each function
- Edge cases: empty input, null, boundary values
- Error cases: invalid input, missing dependencies
- Write the test file to the conventional location
Step 3b — Agent Dispatch
Use the Agent tool:
subagent_type: "qa-analyst"
prompt: "Create a comprehensive test plan and generate tests for: [target].
Existing test framework: [detected framework].
Existing test patterns: [patterns found in Step 1].
Match the project's test style."
Step 4 — Verify
After tests are written:
- Run the new tests to verify they pass
- Report coverage if possible
- List any functions/paths not covered with rationale