Claude Code

Verified against Claude Code · 2026-07-28

Generate tests that actually cover edge cases, not just the happy path

A test-generation prompt that enumerates the edge case categories to hit and forces a table-driven format, countering the well-documented happy-path bias of LLM-written tests.

Claude CodeCursorGitHub CopilotWindsurf

The prompt

Ready to copy — highlighted parts are example details you can swap.

You are writing tests for the code below. Your job is to find where it breaks, not to confirm that it works. A test suite that only exercises the happy path is a failed task, even if every test passes.

TARGET
parseDiscountCode(code, cart) in lib/checkout/discount.ts, returns a DiscountResult

KNOWN EDGE CASES
expired codes, codes with leading or trailing whitespace, valid codes where the cart total is below the minimum spend

REQUIRED COVERAGE
For every public function or branch, explicitly consider it and either test it or state why it does not apply:
- Boundary values: empty, zero, negative, max length, single element versus many.
- Null, undefined, or missing-field inputs, including partially malformed objects.
- Type edge cases the type system does not fully prevent at runtime, such as JSON received from an API.
- Error and exception paths — does the function fail loudly and correctly, or silently do the wrong thing?
- Concurrency or repeat-call cases if the function has any shared or cached state.
- Any case listed under known edge cases above, even if it seems unlikely.

FORMAT
- Table-driven or parametrized tests, one assertion pattern reused across cases, not near-duplicate copy-pasted test functions.
- Name each test case after the behavior it verifies, not test1, test2.
- Do not write snapshot tests unless explicitly asked.
- After the tests, list any coverage gap you could not close and why, for example it requires a live network call or a fixture that does not exist yet.
Customize the highlighted detailsoptional — the prompt above already works

Why this works

Left unconstrained, LLM-generated tests mirror the shape of the code they are testing rather than adversarially probing it — a well-documented bias toward happy-path coverage, because the model is pattern-matching what this function does rather than how this function could be called wrong. Explicitly enumerating edge-case categories such as boundaries, null and undefined, type edge cases, error paths, and concurrency converts an implicit judgment call into an explicit checklist the model has to work through category by category, which is harder to shortcut than an open-ended write tests for this. The known edge cases variable exists because the model cannot know a codebase's actual failure history — a bug you already fixed once is exactly the case worth forcing into the suite by name rather than hoping the model rediscovers it. Requiring table-driven format over copy-pasted test functions is also a coverage mechanism, not just a style preference: a missing row is visually obvious in a table, where a missing near-duplicate function is easy to not notice at all.

Verified against

Claude Code Sonnet 4.6 · 2026-07-28

Cursor 2.0 · 2026-07-29

Changelog

  • 2026-07-29 Initial publish, verified against Claude Code (Sonnet 4.6) and Cursor 2.0.

Building this for real?

This is a free starting point. If you'd rather have custom software built and running for your business, that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
All Claude Code prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY