The prompt
You are a test engineer who is sceptical of code that only has happy-path tests. Write a test suite for the function below. Structure it as: **1. The contract** State in one sentence what the function promises. If the code and the name disagree, say so before writing any tests. **2. Happy path** — two or three cases with typical input. **3. Boundaries** — for every numeric or length parameter, test the lowest valid value, the highest valid value, and one past each. Zero, one, empty, and the maximum are where bugs live. **4. Failure paths** — null, undefined, wrong type, malformed input. Assert the specific error, not merely that something was thrown. **5. Invariants** — properties that must hold for all inputs (round trips, idempotence, ordering, conservation of count). Say which ones apply and test them. **6. What you did not test** — list anything you could not cover and why. Do not pad the suite with tests that cannot fail. Use the testing framework already present in the code. Give each test a name that states the expectation, not the mechanics. --- Function to test: [PASTE YOUR CODE HERE]
Replace everything in [SQUARE BRACKETS] before you run it. The bracketed fields are not optional — they are what the output is built from.
Why this prompt is built this way
Most generated test suites are happy-path tests with the assertions rearranged — they confirm the function does what it does, which catches nothing. This prompt is built almost entirely to prevent that, and its structure is a direct list of the places bugs actually live.
Section 1 is the clever one. Asking the model to state the contract first, and flag any disagreement between the code and its name, catches a whole class of problem before a single test is written: a function called validateEmail that returns true for malformed input has a bug that no test derived from its behaviour will ever find, because such tests encode the bug as expected.
Section 3 names the specific boundary values — zero, one, empty, maximum, and one past each — because "test edge cases" is too vague to act on and produces arbitrary values. Section 5 on invariants pushes toward property-style thinking: round trips, idempotence, conservation of count. These catch bugs that example-based tests miss entirely.
Section 6 is the most unusual instruction, and the tips are right that it is the most useful part. A model that admits it could not reason about your async boundary has told you exactly where to spend your own attention.
What to use it for
- Adding tests to untested code
- Pre-refactor safety net
- Reviewing a thin test suite
- Learning what to test
Adapting it to your situation
- Name the framework and assertion style explicitly. Otherwise you get a generic dialect that runs nowhere.
- Paste one function, not a module. The boundary analysis in section 3 degrades quickly as surface area grows.
- Add your mocking conventions if external dependencies are involved — this is where generated tests most often become unrunnable.
- Keep the "what you did not test" section even when it is inconvenient. Deleting it removes the most honest part of the output.
Where this goes wrong
Generated tests can encode current behaviour as correct behaviour. If the function has a bug, the suite may lock it in — which is why section 1 exists, and why you should read the stated contract before accepting anything below it.
Run every test before trusting the suite. A test that cannot fail is worse than no test, because it buys confidence without providing any.
Which model to run it on
All three handle it. Cursor has the advantage of seeing your existing test files and matching their conventions without being told. Claude tends to produce the most thorough boundary analysis.
Practical tips
Name the framework and assertion style, or you will get a generic one. The "what you did not test" section is the most useful part — it is where you find out the model could not reason about your async boundary or your database mock.