test-gen — Claude Code command: what it does, how to install
test-gen writes test suites against existing code: unit tests for functions, component tests, integration and e2e suites, API tests. Framework and coverage come from flags.
MIT ★ 788 updated 2026-07-03
.claude/commands/test-gen.mdWhat test-gen does
A slash command for Claude that writes tests against code you already have: unit tests for functions, component tests for React/Vue/Angular, integration and e2e suites, plus API tests. Point it at a file with --file, set the kind through --type, choose jest, vitest or playwright in --framework, and send the output elsewhere with --output-dir.
It reads the target first, looking at signatures, dependencies, side effects and error paths, then hands planning to the @test-engineer subagent through the Task tool. That subagent picks the cases, decides how to mock and hunts coverage gaps. Take Task out of the allowed tools and the handoff dies. Generated files arrive with setup and teardown, mocks and CI config.
Unless you pass --coverage, the target sits at 80%. Mocks run on auto or you write them yourself. The command extends the test-generator skill: the skill spots untested code and drops 3-5 starter checks, the command grows them into a full suite.
What it helps with
- write unit tests around boundary values and null input
- cover a component's props and click handlers
- script a login flow as a Playwright e2e test
- push a module's coverage to a set threshold
- stub network calls for integration tests
Example prompts for the agent
- Generate tests for
src/utils/parseDate.ts:/test-gen --file src/utils/parseDate.ts --type unit --framework vitest --coverage 90 - I need component tests for
Cart.tsxwith automatic mocks:/test-gen --file src/components/Cart.tsx --type component --framework jest --mocks auto - Build e2e tests for the orders API into
tests/api:/test-gen --file src/api/orders.ts --type api --framework playwright --output-dir tests/api
How to install test-gen
Manually: put the files in place
.claude/commands/test-gen.mdCall it with /test-gen. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/test-gen.mdCall it with /prompts:test-gen. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/test-gen.prompt.mdManually: put the files in place
.gemini/commands/test-gen.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about test-gen
How do I install test-gen in Claude Code?
Copy the command file into your project at .claude/commands/test-gen.md. Then call it as /test-gen with the flags you need.
What does test-gen do?
It builds test suites for functions, components and APIs: unit, component, integration, e2e and API tests. Case selection and mock strategy go to the @test-engineer subagent.
How is it different from the test-generator skill?
The skill finds untested code and writes 3-5 starter checks. The command builds the full suite with mocks, integration and e2e tests, and works through coverage gaps.
Source text
test-gen.md · MIT
--- allowed-tools: Task, Read, Write, Edit, Bash, Grep, Glob argument-hint: [--file path] [--type unit|component|integration|e2e|api] [--framework jest|vitest|playwright] [--coverage number] [--mocks auto|manual] [--output-dir path] description: Generate comprehensive test suites automatically for components, functions, and APIs with multiple framework support model: inherit --- # Comprehensive Test Suite Generator You are an expert test engineer specializing in creating comprehensive, production-ready test suites across multiple testing frameworks and paradigms. ## Integration with Skills This command builds on test-generator skill's automatic scaffolding: **test-generator Skill (Automatic):** - Detects untested code automatically - Generates basic test scaffolding (3-5 tests) - Suggests obvious test cases **This Command (Comprehensive):** - Invokes `@test-engineer` for full test suites - Advanced patterns (mocking, fixtures, parameterized tests) - Integration and E2E tests - Coverage analysis and gap filling **Workflow:** Skill provides foundation → Command builds comprehensive suite → 90%+ coverage ## Test Generation Process 1. **Code Analysis**: Examine the target code to understand: - Function signatures and behavior - Dependencies and side effects - Edge cases and error conditions - Integration points 2. **Test Strategy**: Use Task tool to coordinate with `@test-engineer` agent for: - Test case identification and prioritization - Mock strategy and dependency management - Coverage analysis and gap identification - Framework-specific best practices 3. **Test Implementation**: Generate complete test files with: - Setup and teardown procedures - Comprehensive test cases including edge cases - Proper mocking and stubbing - Performance and load testing where appropriate ## Arguments Processing - `--file`: Specific file to generate tests for - `--type`: Test type (unit, component, integration, e2e, api, hook, service, utility) - `--framework`: Testing framework (jest, vitest, playwright, cypress, mocha, testing-library) - `--coverage`: Target coverage percentage (default: 80%) - `--mocks`: Mock strategy (auto, manual, none) - `--output-dir`: Directory to save generated tests (default: adjacent to source) ## Supported Test Types ### Unit Tests - Pure function testing with comprehensive input/output coverage - Error handling and boundary conditions - Mathematical edge cases and null/undefined scenarios ### Component Tests (React/Vue/Angular) - Rendering and prop variations - User interaction simulation - State management validation - Accessibility testing integration ### Integration Tests - API endpoint testing with real/mock services - Database interaction validation - External service integration verification - Cross-module communication testing ### End-to-End Tests - Complete user workflow validation - Multi-page application flows - Authentication and authorization scenarios - Performance and load testing ## Framework-Specific Features ### Jest/Vitest ```javascript // Generated test structure with: - describe/test blocks - beforeEach/afterEach setup - Mock functions and modules - Snapshot testing for components - Coverage reporting configuration ``` ### Playwright/Cypress ```javascript // Generated e2e tests with: - Page object model implementation - Cross-browser compatibility - Visual regression testing - Network request interception ``` ### Testing Library ```javascript // Generated component tests with: - User-centric test patterns - Accessibility validation - Event simulation - Query optimization ``` ## Test Quality Standards ### Comprehensive Coverage - **Edge Cases**: Null, undefined, empty values, boundary conditions - **Error Scenarios**: Network failures, validation errors, timeout conditions - **Performance**: Load testing for critical paths, memory leak detection - **Security**: Input validation, XSS prevention, authorization testing ### Best Practices Implementation - **Descriptive Names**: Clear test descriptions and meaningful assertions - **Isolated Tests**: No dependencies between test cases - **Deterministic**: Consistent results across runs - **Fast Execution**: Optimized for CI/CD pipeline performance ## Output Structure Generate complete test files including: 1. **Test Configuration**: Framework setup and configuration files 2. **Mock Definitions**: Reusable mocks and test utilities 3. **Test Cases**: Comprehensive test suites with documentation 4. **CI/CD Integration**: GitHub Actions/GitLab CI test pipeline configs 5. **Coverage Reports**: HTML and JSON coverage report generation ## Advanced Features ### Property-Based Testing - Generate property-based tests for mathematical functions - Random input generation with hypothesis validation - Invariant testing for complex algorithms ### Visual Testing - Screenshot comparison for UI components - Cross-browser visual regression detection - Responsive design validation ### Performance Testing - Load testing with realistic user scenarios - Memory usage and leak detection - API response time validation Focus on generating production-ready, maintainable tests that provide confidence in code quality and catch regressions effectively.
© alirezarezvani · MIT · alirezarezvani/claude-code-tresor