Quick Write Tests
Boost productivity using this write, comprehensive, unit, integration. Includes structured workflows, validation checks, and reusable patterns for testing.
Quick Write Tests
Automatically generate unit tests for a given file or function by analyzing source code, inferring expected behavior, and producing test stubs with assertions.
When to Use This Command
Run this command when...
- You have a new module with no tests and need a starting point quickly
- You want test stubs covering happy paths, edge cases, and error handling
- You are adding coverage to legacy code and need boilerplate generated fast
Avoid this command when...
- You need integration or e2e tests that require full runtime context
- The function depends entirely on external APIs that cannot be mocked automatically
Quick Start
# .claude/commands/quick-write-tests.md --- allowed-tools: ["Bash", "Read", "Write", "Grep"] --- Read the target file, analyze exported functions, and generate a companion test file with test cases for each function.
Example usage:
/quick-write-tests src/utils/validators.ts
Example output:
Analyzing: src/utils/validators.ts
Functions found: validateEmail, validatePhone, validateAge
Generated: src/utils/validators.test.ts
- validateEmail: 4 tests (valid, invalid, empty, unicode)
- validatePhone: 3 tests (valid, invalid format, too short)
- validateAge: 3 tests (valid, negative, non-number)
Total: 10 test cases written
Core Concepts
| Concept | Description |
|---|---|
| Static analysis | Reads function signatures, types, and return values |
| Case generation | Creates happy path, edge case, and error scenario tests |
| Mock inference | Detects dependencies and generates appropriate mock stubs |
| Framework match | Outputs tests matching your existing test framework conventions |
Source File --> Parse Exports --> Analyze Signatures
|
+----------+----------+
| | |
Happy Path Edge Cases Errors
| | |
+--- Generate Tests --+
|
Write Test File
Configuration
| Option | Default | Description |
|---|---|---|
framework | auto | Test framework (jest, vitest, pytest, go-test) |
style | describe | Test structure (describe/it, test, class-based) |
mocks | true | Generate mock implementations for dependencies |
edge-cases | true | Include boundary and edge case tests |
output | adjacent | Where to place test file (adjacent, tests) |
Best Practices
- Review generated tests -- auto-generated tests are a starting point, not a finished product. Validate assertions against real behavior.
- Add domain-specific cases -- the generator handles structural cases but cannot know your business rules.
- Keep mocks minimal -- overly detailed mocks couple tests to implementation details and break on refactors.
- Run generated tests immediately -- catch incorrect assumptions before they become trusted fixtures.
- Use type information -- TypeScript and Python type hints dramatically improve the quality of generated tests.
Common Issues
- Generated tests fail immediately -- the generator infers behavior from signatures, not runtime. Fix assertions to match actual return values.
- Too many trivial tests -- disable edge-cases for simple getter/setter functions that do not need boundary testing.
- Mocks are incomplete -- complex dependency chains may need manual mock setup. Check import resolution paths.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.