Test Generator
When to activate
- You have written a new function, component, or service and need test coverage
- An existing test suite is incomplete or missing tests for critical paths
- You're refactoring code and need to ensure parity with prior behavior via tests
- You need to verify edge cases and error handling paths
When NOT to use
- Tests already exist and are passing — use
/code-review to audit coverage instead
- You're writing integration tests that require external services — scaffold with this skill, then hand-configure environment setup
- The code under test has unstable APIs or incomplete contracts — define the interface first
- You're building a test harness or framework — this skill generates tests, not testing infrastructure
Instructions
Unit Tests
- Read the target function or component — understand the public interface, arguments, return types, and documented behavior
- Identify test categories: happy path, edge cases, error conditions, boundary values, type coercion
- Generate test cases organized by category, each with:
- Descriptive test name (what behavior is being verified)
- Setup (mocks, fixtures, state)
- Assertion (what should be true)
- Write in the project's test framework (Jest, Pytest, Vitest, unittest, etc.)
- Use realistic test data — not lorem ipsum or fake names, but data shapes that match production
Component Tests
For UI components (React, Vue, Svelte):
- Test rendering — does it render without crashing?
- Test props — does each prop affect output correctly?
- Test interaction — clicks, form submission, keyboard navigation
- Test slots/children — if applicable, how does child content render?
- Test accessibility — ARIA labels, semantic HTML, keyboard focus
API Endpoint Tests
- Test each HTTP method — GET, POST, PUT, DELETE (if applicable)
- Test request validation — invalid schemas should fail gracefully
- Test response shape — does output match the documented contract?
- Test status codes — 200, 400, 401, 404, 500 as appropriate
- Test side effects — if the endpoint modifies data, verify the mutation
Coverage Focus
Prioritize tests for:
- Critical paths — happy path, must not break
- Error handling — what happens when input is malformed or service fails?
- Boundary conditions — empty arrays, null values, max/min values
- Authentication/authorization — if applicable
- Data transformations — input → output mapping
Defer or omit tests for:
- Obvious pass-throughs (e.g., a wrapper that just calls another function)
- Third-party library behavior (don't test the library, mock it)
- Trivial getters/setters with no logic
Example
Target code (JavaScript function):
export function parseQueryString(queryString) {
if (!queryString) return {};
return Object.fromEntries(
queryString
.split('&')
.map(pair => pair.split('='))
.map(([key, value]) => [
decodeURIComponent(key),
decodeURIComponent(value || '')
])
);
}
Generated test suite (Jest):
import { parseQueryString } from './query.js';
describe('parseQueryString', () => {
describe('happy path', () => {
it('parses single query parameter', () => {
expect(parseQueryString('name=Alice')).toEqual({ name: 'Alice' });
});
it('parses multiple query parameters', () => {
expect(parseQueryString('name=Alice&age=30&city=NYC')).toEqual({
name: 'Alice',
age: '30',
city: 'NYC'
});
});
});
describe('edge cases', () => {
it('returns empty object for null', () => {
expect(parseQueryString(null)).toEqual({});
});
it('returns empty object for undefined', () => {
expect(parseQueryString(undefined)).toEqual({});
});
it('returns empty object for empty string', () => {
expect(parseQueryString('')).toEqual({});
});
it('handles parameters with no value', () => {
expect(parseQueryString('flag')).toEqual({ flag: '' });
});
it('handles URL-encoded characters', () => {
expect(parseQueryString('email=user%40example.com')).toEqual({
email: 'user@example.com'
});
});
it('handles duplicate keys (last wins)', () => {
expect(parseQueryString('id=1&id=2')).toEqual({ id: '2' });
});
});
describe('error handling', () => {
it('ignores trailing ampersand', () => {
expect(parseQueryString('a=1&')).toEqual({ a: '1' });
});
it('ignores empty pairs between ampersands', () => {
expect(parseQueryString('a=1&&b=2')).toEqual({ a: '1', b: '' });
});
});
});
Why this approach works:
- Tests are independent (no shared state)
- Each test name describes the behavior, not the implementation
- Edge cases are explicit and grouped
- Error conditions are covered
- The suite can run in any order
1---2name: test-generator-23description: Test Generator4metadata:5 source: https://skillmd.com/skills/uitbreidenos/test-generator-26---7# Test Generator89## When to activate1011- You have written a new function, component, or service and need test coverage12- An existing test suite is incomplete or missing tests for critical paths13- You're refactoring code and need to ensure parity with prior behavior via tests14- You need to verify edge cases and error handling paths1516## When NOT to use1718- Tests already exist and are passing — use `/code-review` to audit coverage instead19- You're writing integration tests that require external services — scaffold with this skill, then hand-configure environment setup20- The code under test has unstable APIs or incomplete contracts — define the interface first21- You're building a test harness or framework — this skill generates tests, not testing infrastructure2223## Instructions2425### Unit Tests26271. **Read the target function or component** — understand the public interface, arguments, return types, and documented behavior282. **Identify test categories**: happy path, edge cases, error conditions, boundary values, type coercion293. **Generate test cases** organized by category, each with:30 - Descriptive test name (what behavior is being verified)31 - Setup (mocks, fixtures, state)32 - Assertion (what should be true)334. **Write in the project's test framework** (Jest, Pytest, Vitest, unittest, etc.)345. **Use realistic test data** — not lorem ipsum or fake names, but data shapes that match production3536### Component Tests3738For UI components (React, Vue, Svelte):39401. **Test rendering** — does it render without crashing?412. **Test props** — does each prop affect output correctly?423. **Test interaction** — clicks, form submission, keyboard navigation434. **Test slots/children** — if applicable, how does child content render?445. **Test accessibility** — ARIA labels, semantic HTML, keyboard focus4546### API Endpoint Tests47481. **Test each HTTP method** — GET, POST, PUT, DELETE (if applicable)492. **Test request validation** — invalid schemas should fail gracefully503. **Test response shape** — does output match the documented contract?514. **Test status codes** — 200, 400, 401, 404, 500 as appropriate525. **Test side effects** — if the endpoint modifies data, verify the mutation5354### Coverage Focus5556Prioritize tests for:57- **Critical paths** — happy path, must not break58- **Error handling** — what happens when input is malformed or service fails?59- **Boundary conditions** — empty arrays, null values, max/min values60- **Authentication/authorization** — if applicable61- **Data transformations** — input → output mapping6263Defer or omit tests for:64- Obvious pass-throughs (e.g., a wrapper that just calls another function)65- Third-party library behavior (don't test the library, mock it)66- Trivial getters/setters with no logic6768## Example6970**Target code** (JavaScript function):7172```javascript73export function parseQueryString(queryString) {74 if (!queryString) return {};75 return Object.fromEntries(76 queryString77 .split('&')78 .map(pair => pair.split('='))79 .map(([key, value]) => [80 decodeURIComponent(key),81 decodeURIComponent(value || '')82 ])83 );84}85```8687**Generated test suite** (Jest):8889```javascript90import { parseQueryString } from './query.js';9192describe('parseQueryString', () => {93 describe('happy path', () => {94 it('parses single query parameter', () => {95 expect(parseQueryString('name=Alice')).toEqual({ name: 'Alice' });96 });9798 it('parses multiple query parameters', () => {99 expect(parseQueryString('name=Alice&age=30&city=NYC')).toEqual({100 name: 'Alice',101 age: '30',102 city: 'NYC'103 });104 });105 });106107 describe('edge cases', () => {108 it('returns empty object for null', () => {109 expect(parseQueryString(null)).toEqual({});110 });111112 it('returns empty object for undefined', () => {113 expect(parseQueryString(undefined)).toEqual({});114 });115116 it('returns empty object for empty string', () => {117 expect(parseQueryString('')).toEqual({});118 });119120 it('handles parameters with no value', () => {121 expect(parseQueryString('flag')).toEqual({ flag: '' });122 });123124 it('handles URL-encoded characters', () => {125 expect(parseQueryString('email=user%40example.com')).toEqual({126 email: 'user@example.com'127 });128 });129130 it('handles duplicate keys (last wins)', () => {131 expect(parseQueryString('id=1&id=2')).toEqual({ id: '2' });132 });133 });134135 describe('error handling', () => {136 it('ignores trailing ampersand', () => {137 expect(parseQueryString('a=1&')).toEqual({ a: '1' });138 });139140 it('ignores empty pairs between ampersands', () => {141 expect(parseQueryString('a=1&&b=2')).toEqual({ a: '1', b: '' });142 });143 });144});145```146147**Why this approach works:**148- Tests are independent (no shared state)149- Each test name describes the behavior, not the implementation150- Edge cases are explicit and grouped151- Error conditions are covered152- The suite can run in any order