#What it does
The /test-gen skill analyzes existing code and generates a comprehensive test suite covering happy paths, edge cases, error conditions, and boundary values. Unlike /tdd which writes tests before implementation, /test-gen works with code that already exists -- perfect for adding coverage to untested legacy code or filling gaps in an existing test suite.
#How to use
bash
/test-gen src/lib/pricing.tsbash
/test-gen src/api/orders.ts --coverage 90bash
/test-gen src/components/CheckoutForm.tsx --type integration#What it generates
#Test categories
- Happy path -- Standard inputs that exercise the primary code path
- Edge cases -- Empty arrays, zero values, single-character strings, maximum lengths
- Boundary values -- Off-by-one conditions, pagination limits, timeout thresholds
- Error conditions -- Invalid inputs, network failures, missing permissions, null references
- Concurrency -- Race conditions, duplicate submissions, stale data scenarios
#Test quality rules
- Tests describe behavior, not implementation:
"should return discounted price for gold tier customers" - Each test asserts one thing clearly
- No mocking of the unit under test -- only external dependencies
- Test data is explicit and readable, never hidden behind factory abstractions
- Cleanup and setup are minimal and obvious
#Workflow
- Analyze -- Read the source file, extract all exported functions, identify code paths, branching logic, and external dependencies
- Map Coverage -- Determine which paths need tests: conditionals, early returns, catch blocks, default cases
- Generate -- Write tests organized by function and scenario, using the project's existing test framework and conventions
- Deduplicate -- Check for existing tests that already cover these scenarios. Skip duplicates, fill gaps only
- Verify -- Run the generated tests to confirm they pass against the current implementation
#Example
bash
> /test-gen src/lib/discount.ts
## Generated 8 tests for calculateDiscount()
describe("calculateDiscount", () => {
// Happy path
it("should apply 10% discount for silver tier", ...);
it("should apply 20% discount for gold tier", ...);
it("should apply 0% discount for bronze tier", ...);
// Edge cases
it("should return 0 for zero price", ...);
it("should handle fractional cents correctly", ...);
// Boundary values
it("should cap discount at max discount amount", ...);
// Error conditions
it("should throw for negative price", ...);
it("should throw for unknown tier", ...);
});
## Coverage: 4 branches covered, 0 uncovered#Configuration
- Detects your test framework automatically (Jest, Vitest, Mocha, Playwright, pytest)
- Follows your existing test file naming convention (
*.test.ts,*.spec.ts,__tests__/) - Respects your project's mocking patterns and test utilities