Install this skill: copy and save to ~/.claude/skills/test-generator/SKILL.md

Test Generator

Analyzes a file and generates comprehensive unit tests covering happy path, edge cases, error cases, and boundary conditions.

3 min|Beginner
BuildQuick WinDeveloper
SKILL.md~/.claude/skills/test-generator/
---
name: test-generator
description: |
  Generates comprehensive unit tests for any file or function.
  IMPORTANT: Activate this skill whenever the user asks to "write tests",
  "add tests", "test this function", "test this component", or "generate tests".
  This skill MUST be used for all test generation requests.
---

# Test Generator

Analyzes source code and generates thorough unit tests. Covers the happy path, edge cases, error conditions, and boundary values. Uses whatever test framework the project already has installed.

**Trigger:**

Say any of these to activate this skill:
- "write tests for [file/function]"
- "add tests"
- "test this function"
- "Use skill: test generator"

**How It Works:**

1. Read the target file and identify all exported functions, classes, or components
2. Detect the testing framework (Jest, Vitest, Testing Library, Mocha, etc.)
3. Check for existing test files to match naming conventions and patterns
4. For each function, identify: input types, return types, side effects, error conditions
5. Generate test cases in groups: happy path, edge cases, error handling, boundary conditions
6. Use proper mocking for external dependencies (database calls, API requests, file system)
7. Run the tests to verify they pass
8. Fix any failing tests and re-run

**Guidelines:**

- Use the test framework already in the project (never install a new one)
- Match the test file naming convention (*.test.ts, *.spec.ts, __tests__/*)
- Mock external dependencies, never call real APIs or databases in unit tests
- Test behavior, not implementation details
- Include descriptive test names that explain what scenario is being tested

**Works With:**

- Best with: Claude Code CLI (can run tests and iterate until they pass)
- Also works: Cursor, Windsurf, any AI coding tool
- Expects: A project with a test framework installed and configured

**Output Format:**

- Test file matching the project's naming convention
- Organized by describe/it blocks grouping related scenarios
- All tests passing on first run

Analyzes source code and generates thorough unit tests. Covers the happy path, edge cases, error conditions, and boundary values. Uses whatever test framework the project already has installed.

Say any of these to activate this skill: - "write tests for [file/function]" - "add tests" - "test this function" - "Use skill: test generator"

1. Read the target file and identify all exported functions, classes, or components 2. Detect the testing framework (Jest, Vitest, Testing Library, Mocha, etc.) 3. Check for existing test files to match naming conventions and patterns 4. For each function, identify: input types, return types, side effects, error conditions 5. Generate test cases in groups: happy path, edge cases, error handling, boundary conditions 6. Use proper mocking for external dependencies (database calls, API requests, file system) 7. Run the tests to verify they pass 8. Fix any failing tests and re-run

  • Use the test framework already in the project (never install a new one)
  • Match the test file naming convention (*.test.ts, *.spec.ts, __tests__/*)
  • Mock external dependencies, never call real APIs or databases in unit tests
  • Test behavior, not implementation details
  • Include descriptive test names that explain what scenario is being tested
  • Best with: Claude Code CLI (can run tests and iterate until they pass)
  • Also works: Cursor, Windsurf, any AI coding tool
  • Expects: A project with a test framework installed and configured
  • Test file matching the project's naming convention
  • Organized by describe/it blocks grouping related scenarios
  • All tests passing on first run