Q

Quick Write Tests

Boost productivity using this write, comprehensive, unit, integration. Includes structured workflows, validation checks, and reusable patterns for testing.

CommandClipticstestingv1.0.0MIT
0 views0 copies

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

ConceptDescription
Static analysisReads function signatures, types, and return values
Case generationCreates happy path, edge case, and error scenario tests
Mock inferenceDetects dependencies and generates appropriate mock stubs
Framework matchOutputs tests matching your existing test framework conventions
Source File --> Parse Exports --> Analyze Signatures
                                       |
                            +----------+----------+
                            |          |          |
                       Happy Path  Edge Cases  Errors
                            |          |          |
                            +--- Generate Tests --+
                                       |
                              Write Test File

Configuration

OptionDefaultDescription
frameworkautoTest framework (jest, vitest, pytest, go-test)
styledescribeTest structure (describe/it, test, class-based)
mockstrueGenerate mock implementations for dependencies
edge-casestrueInclude boundary and edge case tests
outputadjacentWhere to place test file (adjacent, tests)

Best Practices

  1. Review generated tests -- auto-generated tests are a starting point, not a finished product. Validate assertions against real behavior.
  2. Add domain-specific cases -- the generator handles structural cases but cannot know your business rules.
  3. Keep mocks minimal -- overly detailed mocks couple tests to implementation details and break on refactors.
  4. Run generated tests immediately -- catch incorrect assumptions before they become trusted fixtures.
  5. Use type information -- TypeScript and Python type hints dramatically improve the quality of generated tests.

Common Issues

  1. Generated tests fail immediately -- the generator infers behavior from signatures, not runtime. Fix assertions to match actual return values.
  2. Too many trivial tests -- disable edge-cases for simple getter/setter functions that do not need boundary testing.
  3. Mocks are incomplete -- complex dependency chains may need manual mock setup. Check import resolution paths.
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates