The test case generator that finds the bugs your happy-path tests miss

Why this prompt matters
Untested edge cases in pricing logic are exactly the kind of bug that reaches production silently and gets discovered when a customer gets charged $0 or a discount stacks incorrectly. A 2024 industry survey found that logic errors in boundary conditions account for a disproportionate share of production incidents precisely because they pass casual manual testing but fail on the exact inputs automated tests are designed to catch.
What we use it for
You just wrote a pricing function for checkout and need a real test suite before it ships, but you have 15 minutes before a deploy window and writing every edge case by hand from scratch would take an hour.
Prompt
Act as a senior QA engineer and test architect with deep experience in [LANGUAGE/FRAMEWORK, e.g. "Python with pytest" or "TypeScript with Jest"]. CONTEXT: Function or feature to test: [PASTE YOUR FUNCTION, CLASS, OR FEATURE DESCRIPTION HERE] What it's supposed to do: [ONE-SENTENCE DESCRIPTION OF THE INTENDED BEHAVIOR] Inputs it receives: [LIST THE PARAMETERS/INPUTS AND THEIR EXPECTED TYPES OR RANGES] Known constraints or business rules: [ANY VALIDATION RULES, RATE LIMITS, OR EDGE CONDITIONS YOU ALREADY KNOW ABOUT] TASK: Generate a comprehensive test suite for this function/feature. Cover four distinct categories of tests: 1. Happy path — normal, expected inputs that should succeed 2. Edge cases — boundary values, empty inputs, maximum/minimum values, unusual-but-valid inputs 3. Error scenarios — invalid inputs, malformed data, and how the function should fail (specific exception types, error codes, or return values) 4. Integration considerations — if this function interacts with external systems (database, API, file system), list what should be mocked and why CONSTRAINTS: - Use the testing framework and idioms specified in the context — do not default to a generic framework - Every test must have a descriptive name that states what it verifies, not just "test1", "test2" - For each test, include a one-line comment explaining WHY that case matters, not just what it checks - Do not generate redundant tests that check the same logical branch twice under different names - Flag any case where you're uncertain about the correct expected behavior rather than guessing silently — mark it with a `# VERIFY:` comment OUTPUT FORMAT: 1. **Test Suite** — complete, runnable test code in the specified framework 2. **Coverage Summary** — a short table listing each test, its category (happy path/edge/error/integration), and what specific risk it catches 3. **Gaps I Couldn't Cover** — a list of scenarios that need clarification from the developer before a test can be written (ambiguous requirements, undocumented behavior, etc.)
Result
Input context: Python function `apply_discount(price: float, discount_pct: float, min_price: float = 0.01) -> float` that applies a percentage discount to a price, but never lets the result drop below `min_price`. Framework: pytest.
1. Test Suite (excerpt):
def test_applies_standard_discount_correctly():
# Verifies the core discount math works for a typical case
assert apply_discount(100.0, 20.0) == 80.0
def test_zero_discount_returns_original_price():
# Edge case: 0% discount should be a no-op, not an error
assert apply_discount(50.0, 0.0) == 50.0
def test_full_discount_respects_minimum_price_floor():
# Edge case: 100% discount would give $0, but min_price floor must apply
assert apply_discount(50.0, 100.0, min_price=1.0) == 1.0
def test_negative_discount_raises_value_error():
# Error case: a negative discount is a business-logic violation, not a valid input
with pytest.raises(ValueError):
apply_discount(50.0, -10.0)
def test_discount_over_100_percent_raises_value_error():
# Error case: discounts above 100% are nonsensical and should be rejected explicitly
with pytest.raises(ValueError):
apply_discount(50.0, 150.0)
def test_negative_price_raises_value_error():
# Error case: negative prices should never reach this function, but defend anyway
with pytest.raises(ValueError):
apply_discount(-10.0, 20.0)
def test_very_small_price_with_discount_stays_above_minimum():
# Edge case: floating point rounding near the min_price boundary
result = apply_discount(0.02, 50.0, min_price=0.01)
assert result >= 0.01
2. Coverage Summary:
| Test | Category | Risk It Catches |
|---|---|---|
| test_applies_standard_discount_correctly | Happy path | Core math is wrong |
| test_zero_discount_returns_original_price | Edge case | Off-by-one logic breaks the no-discount case |
| test_full_discount_respects_minimum_price_floor | Edge case | Price floor silently ignored, allowing $0 sales |
| test_negative_discount_raises_value_error | Error | Invalid input silently accepted, inflating price instead of erroring |
| test_discount_over_100_percent_raises_value_error | Error | Negative resulting price before floor is applied |
| test_negative_price_raises_value_error | Error | Garbage input from an upstream bug propagates silently |
| test_very_small_price_with_discount_stays_above_minimum | Edge case | Floating point rounding pushes result just under the floor |
3. Gaps I Couldn't Cover:
- # VERIFY: Should `discount_pct=100` exactly (not over) be allowed, or does it also need special handling? The spec doesn't say if 100% is a valid edge or an error.
- No information given on whether `price` and `discount_pct` should accept `None` — worth clarifying if this function is called from user input directly.
- Currency rounding behavior (2 decimal places vs raw float) isn't specified — this affects several boundary test assertions and should be confirmed before merging.
Most developers write tests for the cases they already thought of, which means the tests mostly confirm what the developer already believed rather than surfacing what they missed. The gap between "my code passes my tests" and "my code is actually correct" lives almost entirely in the cases nobody thought to write down. This prompt is built specifically to hunt in that gap.
Why four categories instead of just "write tests"
A bare "write unit tests for this function" prompt reliably produces happy-path tests and maybe one obvious error case, because that's the path of least resistance for any writer — human or model. Forcing four explicit categories — happy path, edge cases, error scenarios, integration considerations — changes the search pattern. Edge cases specifically push the model to think about boundaries: zero, negative, maximum, empty, null. Error scenarios push it to think about what should fail loudly rather than fail silently, which is where the costliest bugs tend to hide. Integration considerations catch the class of bug that only shows up when a function's mocked dependency behaves differently than production.
Why the prompt demands a "why" comment on every test
A test suite with fifty tests and no explanation of what each one protects against is nearly as hard to maintain as no tests at all — six months later, nobody knows if a test is load-bearing or vestigial. Requiring a one-line rationale on each test turns the suite into documentation of the function's actual failure modes, which pays off every time someone touches that code later and needs to know what they might break.
Why "Gaps I Couldn't Cover" is the most valuable section
Most test-generation prompts stop at the test code. This one deliberately doesn't, because an AI model generating tests for a function it doesn't fully understand will sometimes guess at intended behavior rather than flag the ambiguity — and a wrong guess baked into a passing test is worse than no test, because it creates false confidence. The explicit instruction to flag uncertainty with a `# VERIFY:` comment, plus a dedicated output section listing unresolved questions, converts silent guessing into an explicit list a developer can resolve in two minutes before merging.
How to adapt it
The prompt is framework-agnostic by design — swap the language/framework field and the model will use pytest, Jest, JUnit, RSpec, or whatever you specify, provided you name it explicitly rather than leaving it implied. For legacy code with no existing tests, feed in the function alongside any call sites you can find, since those often reveal constraints the function signature alone doesn't.