Generate Complete Test Suites from a Function Description

Why this prompt matters
Skipping edge cases is where most production bugs live. A function that works for normal inputs but silently returns wrong results for empty strings, zero values, or concurrent writes will pass a cursory manual test and still break in production. Developers without a structured checklist miss 30-50% of edge cases on average — this prompt enforces completeness every time.
What we use it for
You've just written a pricing function, an authentication handler, or a data-processing pipeline — and you need to ship it tomorrow. You paste the function into this prompt and get back a full test suite with happy paths, boundary values, and error scenarios already written, so you can move to code review instead of spending 90 minutes hand-crafting tests.
Prompt
Act as a senior QA engineer and software testing expert with 10+ years of experience writing test suites for production-grade code. I have a function or feature that needs comprehensive test coverage. Here is the description: [PASTE YOUR FUNCTION/FEATURE DESCRIPTION, CODE SNIPPET, OR SPECIFICATION HERE] Technology stack: [YOUR LANGUAGE AND FRAMEWORK — e.g., Python/pytest, JavaScript/Jest, TypeScript/Vitest, Java/JUnit, Go/testing] Testing framework: [YOUR TESTING FRAMEWORK] Code maturity: [NEW CODE / EXISTING CODE WITH KNOWN BUGS / REFACTORING IN PROGRESS] Your task: 1. Generate a complete set of unit tests covering: - Happy path (standard inputs with expected outputs) - Edge cases (boundary values, empty inputs, maximum inputs, special characters) - Error scenarios (invalid inputs, type mismatches, null/undefined, out-of-range values) - State mutations (if the function has side effects, test them explicitly) 2. List integration test outlines (what you'd test at the integration layer, without writing full code) 3. Identify any untestable scenarios and explain why (dependency on external systems, timing issues, etc.) 4. Add a one-line comment above each test explaining what it's asserting and why it matters Constraints: - Tests must be independent — no test should rely on another's side effects - Use descriptive test names in the format: [method]_[scenario]_[expected outcome] - Do NOT mock anything unless you explain exactly why the mock is necessary - Prioritize tests by impact: mark each as HIGH / MEDIUM / LOW risk Output format: ## Unit Tests (with priority labels) [Full test code in [YOUR TESTING FRAMEWORK]] ## Integration Test Outlines [Bullet list of integration scenarios to cover] ## Untestable Scenarios [List with explanations] ## Coverage Summary [Estimated line/branch coverage and what's missing]
Result
<p>Here is the full test suite for <code>calculate_discount(price, coupon_code, user_tier)</code> using Python/pytest:</p><pre><code>import pytest
from pricing import calculate_discount
# [HIGH] Standard discount applied correctly for a valid coupon and premium user
def test_calculate_discount_valid_coupon_premium_user_applies_discount():
assert calculate_discount(100.0, "SAVE20", "premium") == 80.0
# [HIGH] Free users receive no additional tier discount beyond coupon
def test_calculate_discount_valid_coupon_free_user_no_tier_bonus():
assert calculate_discount(100.0, "SAVE20", "free") == 80.0
# [HIGH] Invalid coupon code returns full price without discount
def test_calculate_discount_invalid_coupon_returns_full_price():
assert calculate_discount(100.0, "FAKECODE", "premium") == 100.0
# [HIGH] Price of zero returns zero regardless of coupon or tier
def test_calculate_discount_zero_price_returns_zero():
assert calculate_discount(0.0, "SAVE20", "premium") == 0.0
# [MEDIUM] Negative price raises ValueError — cannot discount negative amounts
def test_calculate_discount_negative_price_raises_value_error():
with pytest.raises(ValueError, match="Price must be non-negative"):
calculate_discount(-50.0, "SAVE20", "premium")
# [MEDIUM] Empty coupon string treated as no coupon — full price returned
def test_calculate_discount_empty_coupon_no_discount():
assert calculate_discount(100.0, "", "premium") == 100.0
# [MEDIUM] None coupon treated as no coupon — does not raise, returns full price
def test_calculate_discount_none_coupon_no_discount():
assert calculate_discount(100.0, None, "premium") == 100.0
# [MEDIUM] Unknown user_tier defaults to free-tier behavior, no tier bonus
def test_calculate_discount_unknown_tier_defaults_to_free():
assert calculate_discount(100.0, "SAVE20", "vip") == 80.0
# [LOW] Very large price value does not cause overflow or floating-point error
def test_calculate_discount_very_large_price_precision():
result = calculate_discount(1_000_000.0, "SAVE20", "premium")
assert abs(result - 800_000.0) < 0.01
# [LOW] Coupon code is case-insensitive — "save20" works like "SAVE20"
def test_calculate_discount_coupon_case_insensitive():
assert calculate_discount(100.0, "save20", "premium") == 80.0
</code></pre><h2>Integration Test Outlines</h2><ul><li>Apply coupon from the database — verify the discount matches the stored percentage for that coupon record</li><li>Apply discount to a cart with multiple line items — verify totals are recalculated correctly</li><li>Expired coupon in the database — verify <code>calculate_discount</code> returns full price and logs the expiry event</li><li>Concurrent requests with the same coupon (single-use coupon) — verify only one request succeeds</li></ul><h2>Untestable Scenarios</h2><ul><li><strong>Real-time coupon expiry race condition</strong> — coupon expires between the validity check and the discount application; requires a database transaction test outside unit scope</li><li><strong>External pricing API availability</strong> — if <code>calculate_discount</code> calls a third-party pricing service, that call cannot be reliably tested without a staging environment</li></ul><h2>Coverage Summary</h2><p>Estimated line coverage: <strong>94%</strong>. Estimated branch coverage: <strong>87%</strong>. Missing: the internal retry logic on database timeout (lines 47-52) — requires a mock of the DB connection pool, which should be covered in an integration test.</p>
<p>Writing tests is one of those tasks developers know they should do thoroughly and rarely do. Not out of laziness — out of time pressure and the cognitive overhead of enumerating every edge case from scratch. This prompt offloads that enumeration to the AI so you can focus on reviewing the output rather than generating it.</p><h2>What Makes This Prompt Different</h2><p>Most "write tests for this code" prompts return a handful of happy-path assertions and call it done. This prompt forces a different contract: the AI must work through four distinct categories before it can finish — happy path, edge cases, error scenarios, and state mutations. That structure catches the 30-50% of edge cases developers routinely miss when writing tests under time pressure.</p><p>The output format matters too. Requiring descriptive test names in the <code>[method]_[scenario]_[expected outcome]</code> pattern ensures the test suite is readable months later, when the original author is long gone. Requiring an explanatory comment on each test means a new developer can understand what each assertion is protecting against — not just what it does.</p><h2>How to Use It</h2><p>Paste your function, a plain-English description, or even a spec document into the bracketed field. Specify your language and framework — the AI will produce runnable code, not pseudocode. Set the code maturity flag to <code>EXISTING CODE WITH KNOWN BUGS</code> and the AI will also identify likely defect-prone paths based on the code structure.</p><p>The mock constraint is deliberate. Mocking everything is the easiest way to build a test suite that passes but provides no confidence. By requiring the AI to justify any mock it introduces, you keep the test suite grounded in real behavior.</p><h2>Priority Labels</h2><p>Each test gets a HIGH / MEDIUM / LOW risk label. This lets you skip LOW tests during a time-constrained release and come back to them in the next sprint — without losing track of what was skipped. It also makes code review faster: reviewers can spot at a glance whether the HIGH-risk paths are covered.</p><h2>Works Best With</h2><p>Claude Sonnet 4.6 or GPT-4o. For complex functions with deeply nested conditionals, Claude tends to produce more thorough branch coverage. For greenfield code in newer frameworks, GPT-4o is equally capable. Both models handle this prompt reliably — do not use a smaller model for this task, as they frequently omit error scenarios.</p>