test-generator
npx skills add https://github.com/nimiusrd/agent-skills --skill test-generator
Agent 安装分布
Skill 文档
Test Generator
Automatically create or update tests for files changed in the current branch, iterating until statement coverage reaches the target threshold (default 80%).
Workflow
- Detect changed files â run
scripts/detect-changes.sh [base-branch] - Discover project conventions â read existing tests, test config, and setup files
- Write / update tests â for each uncovered file, create or extend its test file
- Run coverage check â run
scripts/check-coverage.sh <threshold> [files...] - Iterate â if any file is below threshold, read the coverage report, add missing tests, repeat from step 4 (max 3 iterations)
- Report â summarize final per-file coverage to the user
Step 1 â Detect Changed Files
bash <skill-path>/scripts/detect-changes.sh main
- Pass the base branch as argument (defaults to upstream or
main). - Output: one source file path per line.
- Filters out: test files, config, styles, assets, lock files,
__mocks__/,test/setup.
If no files are output, inform the user there are no testable changes.
Step 2 â Discover Project Conventions
Before writing any test, read these to match existing style:
- Test config â
vitest.config.*,vite.config.*(test section),Cargo.toml - Test setup â files referenced by
setupFilesin config - Existing test for the file â
<name>.test.ts,<name>.spec.ts, or__tests__/<name>.ts - Neighboring tests â 1-2 test files in the same directory for style reference
- Project rules â
AGENTS.md,CLAUDE.md,.eslintrc*,eslint.config.*
Key things to extract:
- Test framework and assertion style (e.g.
expect(),assert) - Import conventions (
import { describe } from 'vitest'vs globals) - Mock patterns (manual mocks,
vi.mock()) - File naming:
*.test.tsvs*.spec.ts - Any JSDoc / lint requirements on test files
Step 3 â Write / Update Tests
For each changed file without sufficient coverage:
If no test file exists â create one following the project naming convention.
If a test file exists â add new test cases; do not rewrite existing passing tests.
Test quality guidelines
- Test behavior, not implementation details.
- Cover: happy path, edge cases, error paths, boundary values.
- Use descriptive
describe/itblock names that explain the expected behavior. - For React components: prefer
@testing-library/reactqueries (getByRole,getByText) overquerySelector. - For functions: test return values and side effects, not internal calls.
- Mock external dependencies (API, file system, DB) but not the unit under test.
- If the project uses
fast-check, consider property tests for pure utility functions (name:*.property.test.ts).
Step 4 â Run Coverage Check
bash <skill-path>/scripts/check-coverage.sh 80 src/services/foo.ts src/utils/bar.ts
- First argument: threshold percentage.
- Remaining arguments: filter output to only these files.
- Output lines:
PASS 92.3% src/services/foo.tsorFAIL 65.0% src/utils/bar.ts.
If the script fails to find coverage output, check that the coverage provider is installed
(@vitest/coverage-v8, @vitest/coverage-istanbul, etc.) and install if missing.
Step 5 â Iterate
For each FAIL file:
- Read the coverage JSON (
coverage/coverage-final.jsonfor vitest) to identify uncovered statements. - Add targeted test cases for uncovered branches/statements.
- Re-run coverage check.
- Repeat up to 3 iterations total. If still below threshold after 3 iterations, report remaining gaps to the user with suggestions.
Step 6 â Report
Summarize results:
## Test Coverage Report
| File | Coverage | Status |
|------|----------|--------|
| src/services/foo.ts | 92.3% | PASS |
| src/utils/bar.ts | 81.0% | PASS |
| src/components/Baz.tsx | 73.5% | FAIL |
Target: 80% | Passed: 2/3
For FAIL files, briefly explain what remains uncovered and suggest next steps.
Scripts
scripts/detect-changes.sh [base-branch]â list changed source files needing testsscripts/check-coverage.sh <threshold> [files...]â run tests with coverage and report per-file results