IRCNF
Claude Sonnet 4.5 (also works with GPT-4o and Gemini 2.5 Pro)You wrote a function or shipped a feature and need full test coverage before merging. You have the code in front of you but writing tests feels slow — you keep forgetting edge cases and your PR review always comes back with 'what about null input?' or 'does this handle timeout?'Developer Tools

Generate a complete test suite from any function or feature description

Share:
Generate a complete test suite from any function or feature description

Why this prompt matters

<p>Incomplete tests are the leading cause of regressions in production. A typical developer writing tests from memory covers 60-70% of edge cases — the remaining 30% is where bugs live. Every missed edge case is a future incident, a 2am page, or a data corruption bug discovered by a customer. Beyond bugs: code without proper tests blocks confident refactoring. You end up with unmaintainable spaghetti because nobody dares touch it. This prompt forces systematic coverage across happy paths, boundaries, failures, and integration points — the same coverage a dedicated QA engineer would produce in several hours, generated in under a minute.</p>

What we use it for

You wrote a function or shipped a feature and need full test coverage before merging. You have the code in front of you but writing tests feels slow — you keep forgetting edge cases and your PR review always comes back with 'what about null input?' or 'does this handle timeout?'

Prompt

Act as a senior software engineer and QA architect with deep expertise in test-driven development.

Context:
I have a [FUNCTION / FEATURE / MODULE] that I need fully tested. It is written in [PROGRAMMING LANGUAGE] and uses [FRAMEWORK / LIBRARY if any]. Here is the code or description:

[PASTE YOUR FUNCTION OR FEATURE DESCRIPTION HERE]

Task:
Generate a comprehensive test suite for the above. Cover ALL of the following:
1. Happy-path unit tests
2. Edge case unit tests
3. Error/failure scenarios
4. Integration test outlines
5. Security-relevant tests if applicable

Constraints:
- Write tests in [TEST FRAMEWORK, e.g. Jest, pytest, JUnit]
- Name tests: should_[expected behavior]_when_[condition]
- Do NOT write implementation code
- Group tests into describe blocks by category
- Flag any testability issues in the original code

Output Format:
- Full runnable test file with all imports
- Section comments: // === HAPPY PATH ===, // === EDGE CASES ===, etc.
- Summary table: test count per category + estimated code coverage %
- Testability issue flags

<h2>The problem with writing tests by hand</h2><p>Ask any developer what they skip when they're under deadline pressure, and tests come up every time. Not because developers don't care about quality — they do — but because writing comprehensive tests is tedious, repetitive, and mentally taxing. You need to think in opposites: what breaks this? What did I not account for? Most developers in that mode miss 30-40% of meaningful edge cases.</p><p>This prompt solves that by putting a senior QA engineer's systematic thinking into a reusable template.</p><h2>What makes this prompt effective</h2><p>The prompt uses a five-category coverage framework: happy path, edge cases, errors, integration, and security. Each category maps to a different failure mode in production. The constraint to name tests using <code>should_[behavior]_when_[condition]</code> forces the AI to be precise rather than generating vague test names like <code>test_1</code> or <code>testFunction_works</code>. The requirement to flag testability issues catches architectural problems — like tightly coupled dependencies — before they become technical debt.</p><h2>How to use it</h2><p>Paste the prompt into Claude Sonnet 4.5 (or GPT-4o). Fill in the three bracketed fields: your programming language, your test framework, and the function or feature description. For a function, paste the actual code. For a feature, paste the acceptance criteria or a plain-English description of what it does.</p><p>The output is a ready-to-run test file plus a coverage summary table. Run it, check the outline tests that need fleshing out, and you have a baseline test suite in minutes rather than hours.</p><h2>Adapting for different languages and frameworks</h2><p>The prompt works equally well across ecosystems. For Python, specify <code>pytest</code> as the framework. For TypeScript, use <code>Jest</code> or <code>Vitest</code>. For Java, use <code>JUnit 5</code>. For Go, just say <code>Go testing package</code>. The output structure adapts accordingly — the AI knows the idioms for each framework and will use the correct assertion style, mock patterns, and file organization.</p><h2>Example output preview</h2><p>For a <code>calculateDiscount(price, memberTier)</code> function in TypeScript with Jest, the prompt generates roughly 18-24 tests covering: standard price/tier combinations, zero-price inputs, negative prices, invalid tier strings, null parameters, floating-point boundary cases, and the integration contract with the pricing service. The summary table shows estimated line coverage above 90%.</p>

testingdeveloper toolsunit-testsclaudecoding
Share: