Write a comprehensive unit test suite for a function
A test suite that only checks the happy path proves the function works when nothing goes wrong, which was never really in question.
- Use it for
- Anyone who needs real unit test coverage for a function, not just a couple of obvious happy-path checks.
Unit tests written quickly tend to check the happy path — the input the function was obviously designed to handle — which confirms the easy part works but says nothing about what actually breaks in practice: null values, empty collections, boundary numbers, malformed input. This prompt writes a genuinely comprehensive suite that targets those categories deliberately, not just whatever's easiest to write.
When not to use this
For a trivial, side-effect-free function where edge cases genuinely don't apply (a pure constant, say), comprehensive edge-case testing is overkill.
Fill in
Here's the function: {{code}}
Testing framework: {{framework}}
Write a comprehensive unit test suite for this — the happy path,
null or missing inputs, boundary values, and at least one realistic
failure mode specific to what this function does. Tell me if any part
of the function is genuinely untestable as written and would need a
small change to test properly.Why it works
Naming the specific categories to cover — null inputs, boundaries, a realistic failure mode — rather than asking generically for "tests," is what produces a suite that actually protects against real bugs instead of one that technically has good line coverage while missing the inputs most likely to break the function in production.
Common mistakes
- ×Accepting a test suite that only covers the happy path and calling it comprehensive.
- ×Not testing boundary values specifically (zero, negative numbers, empty collections) where off-by-one errors actually live.
Follow-ups
- One of these tests is failing on the current code — help me figure out if it's a real bug or an incorrect test.
- Write the same kind of comprehensive suite for this related function: {{related_code}}.
Did this work?
The suite covers the happy path, null or missing inputs, boundary values, and at least one realistic failure mode — not just the obvious case the function was clearly designed for.
Tested on claude-opus-5. Evidence status is draft; it moves to battle-tested only on recorded runs, never by hand.