active
Test Generator
Safe
System VerifiedSafe
Analyzes source code and generates comprehensive unit tests. Auto-detects framework (Vitest/Jest/pytest/Go), handles mocking, covers edge cases.
@api/test-generator
testing
tdd
generator
devtools
Test Generator
Purpose: Analyze source code and generate comprehensive unit tests following the project's testing conventions.
Invocation
code
/test-gen <file_path> [--framework vitest|jest|pytest|go]
Process
Step 1: Analyze the Target
Read the source file and identify:
- All exported functions/classes/methods
- Input types and return types
- Edge cases from conditional branches
- Dependencies that need mocking
- Existing test file (if any) to avoid duplicates
Step 2: Determine Testing Framework
Auto-detect from project config:
vitest.config.*→ Vitestjest.config.*orpackage.json[jest]→ Jestpytest.iniorpyproject.toml[tool.pytest]→ pytest*_test.gofiles → Go testing
Step 3: Generate Test Cases
For each function, generate:
- Happy path — typical valid input → expected output
- Edge cases — empty input, zero, null/undefined, boundary values
- Error paths — invalid input → expected error/exception
- Type variations — different valid types if function accepts union types
Step 4: Structure the Test File
typescript
import { describe, it, expect, vi } from 'vitest'
import { targetFunction } from '../path/to/source'
describe('targetFunction', () => {
it('returns expected result for valid input', () => {
expect(targetFunction('valid')).toBe('expected')
})
it('throws on null input', () => {
expect(() => targetFunction(null)).toThrow()
})
it('handles empty string', () => {
expect(targetFunction('')).toBe('')
})
})
Mocking Strategy
- External APIs: Always mock with
vi.mock()orjest.mock() - Database calls: Mock the client/ORM, not the database
- File system: Mock
fsoperations, never touch real files - Time: Use
vi.useFakeTimers()for time-dependent logic - Environment variables: Set via
vi.stubEnv()or test setup
Rules
- Match the project's existing test style (describe/it vs test, assertion style)
- Place test files adjacent to source (
*.test.ts) or intests/mirror - Never generate snapshot tests unless explicitly asked
- Aim for branch coverage, not just line coverage
- Each test should be independent — no shared mutable state
- Test names should describe behavior, not implementation
Dormant$0/mo
$20 more to next tier
Created by
Info
Created February 18, 2026
Version 1.0.0
User-invoked
Terminal output
Embed
Add this skill card to any webpage.
<iframe src="https://skillslap.com/skill/ca99c744-1e00-4174-a6fe-f74f595da30c/embed"
width="400" height="200"
style="border:none;border-radius:12px;"
title="SkillSlap Skill: Test Generator">
</iframe>