All tools
SkillCurated · reviewed
Test Generation Skill
Updated Jul 7, 2026
A Claude Code skill that generates unit or integration tests for a function or diff. It derives test cases from the implementation: the happy path first, then edge cases and failure paths the code explicitly handles or should handle.
What it does
- /gen-tests
Generate unit/integration tests for the current selection or pasted function, covering happy path, edges, and failures.
- /gen-tests <scope>
Generate tests for a named function, file, or diff; optionally specify the test framework.
Files (1)
SKILL.mdprimary · markdown · 3.4 KB
# Test Generation Skill
---
slug: test-generation-skill
version: 1.0.0
category: engineering
command: /gen-tests
---
## What it does
Generates unit or integration tests from a function signature, implementation, or diff.
Produces tests that would fail before the code was written and pass after — not tests
that are tautologically true regardless of the implementation.
## Trigger
Use this skill when asked to write, generate, or add tests.
Typical invocations:
- "Write tests for this function"
- "Generate tests for the changes in this diff"
- `/gen-tests` in Claude Code
- `/gen-tests <scope>` where scope is a function name, file, or concern
## Input
Provide one or more of:
1. The function or module to test (pasted code or file path)
2. A diff of the changes that need test coverage
3. The test framework in use (Jest, Vitest, pytest, Go testing, etc.)
4. Any existing tests to match style
If the code is not provided, ask for it before proceeding. Infer the framework from
imports or project structure if not stated.
## Method
For each function under test:
1. **Happy path** — the expected behavior when inputs are valid and preconditions are met.
2. **Edge cases** — boundary values, empty collections, zero, null/undefined, max lengths, type coercions.
3. **Failure paths** — inputs that should throw, reject, or return an error; side effects on failure.
4. **Mocks and stubs** — identify external dependencies (DB, HTTP, filesystem) and provide minimal mocks.
Do not generate tests that only verify the implementation restates itself (e.g., testing that `add(1, 2)` returns `1 + 2`). Each test must encode a business rule or constraint.
## Output format
Produce a single test file matching the detected framework's conventions.
Group tests in `describe` blocks by function or concern. Each test name states the rule it encodes:
```
describe('<functionName>', () => {
it('<plain-English rule being verified>', () => { ... });
});
```
After the file, add a short **Coverage notes** section listing any cases you could not test
without more context (e.g., "network timeout path requires a mock HTTP server not shown here").
## Example output
```typescript
import { describe, it, expect } from 'vitest';
import { applyDiscount } from './pricing';
describe('applyDiscount', () => {
it('returns the original total when no discount code is provided', () => {
expect(applyDiscount({ total: 100 }, '')).toEqual({ total: 100 });
});
it('reduces the total by the rate for a valid code', () => {
expect(applyDiscount({ total: 100 }, 'SAVE20')).toEqual({ total: 80 });
});
it('returns zero total when the rate is 100%', () => {
expect(applyDiscount({ total: 50 }, 'FREE100')).toEqual({ total: 0 });
});
it('ignores an unknown code and leaves the total unchanged', () => {
expect(applyDiscount({ total: 100 }, 'NOTACODE')).toEqual({ total: 100 });
});
it('does not mutate the original order object', () => {
const order = { total: 100 };
applyDiscount(order, 'SAVE20');
expect(order.total).toBe(100);
});
});
```
**Coverage notes**: The negative-total guard in `validateOrder` is not tested here because that
function is out of scope for this diff. Add a test for it in the `validateOrder` describe block.
## Commands (Claude Code)
- `/gen-tests` — Generate tests for the current selection or pasted function.
- `/gen-tests <scope>` — Generate tests for a named function, file, or diff; optionally specify the framework.