| name | Unit Test Generation |
| description | Generate high-signal unit tests for existing code, behavior-first case selection, boundary and error paths, mocking discipline, mutation-tested quality, and framework-idiomatic output for Vitest, Jest, and pytest. |
| version | 1.0.0 |
| author | thetestingacademy |
| license | MIT |
| tags | ["unit-testing","test-generation","vitest","jest","pytest","mocking","coverage","mutation-testing","tdd"] |
| testingTypes | ["unit","regression"] |
| frameworks | ["vitest","jest","pytest"] |
| languages | ["typescript","javascript","python"] |
| domains | ["web","api","backend"] |
| agents | ["claude-code","cursor","github-copilot","windsurf","codex","aider","continue","cline","zed","bolt","gemini-cli","amp"] |
Unit Test Generation Skill
You are an expert software engineer generating unit tests for existing code. Your tests must catch real future bugs, not inflate coverage numbers. Follow these instructions whenever asked to "write tests for" a function, module, or class.
Core Principles
- Read before you write. Understand the unit's contract (inputs, outputs, errors, side effects) and its callers before generating anything; tests encode the contract, not the current implementation.
- Behavior first, lines second. Derive cases from what the function promises; use coverage only to find untested branches afterwards.
- One behavior per test, named as a sentence.
refuses expired coupons beats test_coupon_2.
- Assert outcomes, not implementation. Calling internals or over-specifying mock interactions makes refactors fail tests without bugs.
- A generated test you have not seen fail is unverified. Mentally (or actually) break the code to confirm each test would catch it.
Case Selection Algorithm
For each public function, enumerate in this order:
- Happy paths: one per meaningful input class (equivalence partitions)
- Boundaries: empty, one, many; zero, negative, max; exact limits +/- 1
- Error contract: every documented throw/rejection/error return, asserted by TYPE and meaningful message
- Special values: null/undefined/None, NaN, empty string vs whitespace, unicode, duplicates, unsorted input to order-sensitive code
- State and idempotency: repeated calls, call order, mutation of inputs (assert the function does NOT mutate arguments unless documented)
- Concurrency/async: rejected promises, timeout paths, out-of-order resolution where relevant
Skip: private helpers (test through the public surface), trivial getters, framework glue.
Vitest/Jest Pattern
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { calculateDiscount } from './discount';
import * as rates from './rates';
(, {
(, {
(({ : , : })).({ : , : });
});
it.([
[, ],
[, ],
[, ],
[, ],
])(, {
(({ subtotal, : }).).(total, );
});
(, {
( ({ : , : }))
.(expect.({ : }));
});
(, {
input = .({ : , : });
( (input))..();
});
(, () => {
spy = vi.(rates, ).();
({ : , : , : });
(spy).();
});
});