Test Generator
Overview
Analyze existing source code and automatically generate comprehensive test suites with unit tests, edge cases, mocks, and integration scenarios for the specified testing framework.
When to Use
- Adding tests to a legacy codebase with zero coverage
- Generating test scaffolding after writing new features
- Bootstrapping a test suite before a major refactor
- Creating regression tests from bug reports
- Ensuring API endpoint coverage before deployment
Instructions
- Accept inputs: source file path(s) or directory, test framework (jest/pytest/vitest/playwright), coverage target (%), test type (unit/integration/e2e/all).
- Parse the source code to identify: functions, classes, methods, API routes, exported interfaces.
- For each function/method: analyze inputs, outputs, side effects, and error conditions.
- Generate test cases covering: happy path, edge cases (null, empty, boundary values), error/exception paths.
- Generate mocks for external dependencies (databases, APIs, file system).
- For API routes: generate request/response tests with valid and invalid payloads.
- Write test files following the project's naming convention (e.g.,
*.test.ts, test_*.py).
- Return coverage estimate, test file paths, and list of untestable code sections.
Environment
TEST_FRAMEWORK=jest
SOURCE_DIR=./src
OUTPUT_DIR=./tests
COVERAGE_TARGET=80
INCLUDE_MOCKS=true
Examples
Input:
file: ./src/api/orders.ts
framework: jest
type: unit+integration
coverage_target: 85
Output:
Test suite generated: ./tests/api/orders.test.ts
Test cases: 24 (18 unit, 6 integration)
Edge cases covered: null inputs, empty arrays, 404/500 responses
Mocks generated: supabase client, stripe API
Estimated coverage: 87%
1---2name: test-generator3description: Automatically generate unit, integration, and end-to-end tests for existing code. Analyzes functions, classes, and API routes to produce test suites in Jest, Pytest, Vitest, or Playwright with edge cases and mocks.4license: MIT5---67# Test Generator89## Overview1011Analyze existing source code and automatically generate comprehensive test suites with unit tests, edge cases, mocks, and integration scenarios for the specified testing framework.1213---1415## When to Use1617- Adding tests to a legacy codebase with zero coverage18- Generating test scaffolding after writing new features19- Bootstrapping a test suite before a major refactor20- Creating regression tests from bug reports21- Ensuring API endpoint coverage before deployment2223---2425## Instructions26271. Accept inputs: source file path(s) or directory, test framework (jest/pytest/vitest/playwright), coverage target (%), test type (unit/integration/e2e/all).282. Parse the source code to identify: functions, classes, methods, API routes, exported interfaces.293. For each function/method: analyze inputs, outputs, side effects, and error conditions.304. Generate test cases covering: happy path, edge cases (null, empty, boundary values), error/exception paths.315. Generate mocks for external dependencies (databases, APIs, file system).326. For API routes: generate request/response tests with valid and invalid payloads.337. Write test files following the project's naming convention (e.g., `*.test.ts`, `test_*.py`).348. Return coverage estimate, test file paths, and list of untestable code sections.3536---3738## Environment3940```41TEST_FRAMEWORK=jest42SOURCE_DIR=./src43OUTPUT_DIR=./tests44COVERAGE_TARGET=8045INCLUDE_MOCKS=true46```4748---4950## Examples5152**Input:**53```54file: ./src/api/orders.ts55framework: jest56type: unit+integration57coverage_target: 8558```5960**Output:**61```62Test suite generated: ./tests/api/orders.test.ts63Test cases: 24 (18 unit, 6 integration)64Edge cases covered: null inputs, empty arrays, 404/500 responses65Mocks generated: supabase client, stripe API66Estimated coverage: 87%67```