add-tests
SKILL.md
Skill: Add Tests
What This Skill Does
Generates tests that fit the project, not generic boilerplate. Analyzes the target code, discovers the project's test framework and patterns (file naming, fixture usage, assertion style), then generates tests that look like they were written by a team member.
When to Use
- After implementing new code that needs tests
- When
coverage-checkidentifies untested modules - When the user says "add tests for X"
- As part of
implement-phase(after each code change)
Do NOT use this for test strategy planning — use test-strategy for that.
Execution Model
- Always: the primary agent runs this skill directly.
- Rationale: test generation requires reading source code, understanding execution context, and running tests to verify they pass.
- Output: test files in the project's test directory.
Workflow
Step 1: Detect Test Infrastructure
Identify the project's test setup:
JavaScript/TypeScript:
# Framework
grep -l "vitest\|jest\|mocha" package.json
# Config
find . -name "vitest.config.*" -o -name "jest.config.*" | head -5
# Existing tests
find . -path "*/test*" -name "*.test.*" -o -name "*.spec.*" | head -10
Python:
# Framework
grep -l "pytest\|unittest" pyproject.toml setup.cfg
# Config
find . -name "conftest.py" -o -name "pytest.ini" | head -5
# Existing tests
find . -path "*/test*" -name "test_*" | head -10
Step 2: Analyze Existing Test Patterns
Read 2-3 existing test files to extract patterns:
- File naming:
test_<module>.pyvs<module>.test.tsvs<module>.spec.ts - Directory structure:
tests/unit/,tests/integration/,__tests__/, co-located - Import style: relative vs absolute, aliases
- Fixture patterns: pytest fixtures, beforeEach, test factories
- Assertion style: assert, expect, should
- Mocking approach: unittest.mock, jest.mock, vitest vi.mock
- Test organization: describe/it blocks, class-based, function-based
Step 3: Analyze Target Code
Read the module/function to test:
- Public interface: exported functions, class methods, API endpoints
- Input types: what parameters does it accept?
- Output types: what does it return?
- Side effects: does it write files, call APIs, modify state?
- Error cases: what exceptions/errors can it throw?
- Edge cases: null inputs, empty arrays, boundary values
- Dependencies: what does it import? (need mocking?)
Step 4: Design Test Cases
Create test cases covering:
| Category | Test Cases |
|---|---|
| Happy path | Normal inputs → expected outputs |
| Edge cases | Empty input, null, boundary values |
| Error handling | Invalid input, missing dependencies |
| Integration | Interaction with dependencies (if applicable) |
Step 5: Generate Tests
Write the test file following the discovered patterns:
- Use the same file naming convention
- Use the same import style
- Use the same fixture/setup patterns
- Use the same assertion style
- Add clear test names that describe the behavior being tested
Step 6: Run and Verify
Run the generated tests:
# Python
pytest <test-file> -v
# JavaScript
npx vitest run <test-file>
If tests fail:
- Import errors: fix paths
- Type errors: fix mocks/fixtures
- Assertion errors: verify expected values against actual implementation
- Do NOT change the source code to make tests pass — fix the tests
Step 7: Report Coverage
Show what was covered:
Tests generated: <file>
- <N> test cases
- Happy path: <Covered/Not Covered>
- Edge cases: <Covered/Not Covered>
- Error handling: <Covered/Not Covered>
Rules
- Match project patterns: generated tests must look like existing tests in the project. Never introduce a different framework, style, or structure.
- Test behavior, not implementation: test what the function does, not how it does it. Avoid testing private internals.
- Tests must pass: run tests after generating them. Failing generated tests are worse than no tests.
- Don't modify source code: if a function is hard to test, note it — don't refactor the source to make it testable (that's
refactor's job). - Meaningful names: test names should read as behavior descriptions:
test_returns_empty_list_when_no_items_match. - No built-in explore agent: do NOT use the built-in
exploresubagent type.
Weekly Installs
1
Repository
flitzrrr/openco…g-skillsGitHub Stars
1
First Seen
13 days ago
Security Audits
Installed on
amp1
cline1
opencode1
cursor1
kimi-cli1
codex1