Skip to content
Promptnic
#50 overall#9 in Coding & DevBeginnerChain-of-Thought

Tests That Actually Catch Regressions

Generates a focused test suite around behaviour, edge cases and failure modes instead of shallow coverage padding.

Open in:ChatGPTClaudeGrokPerplexity

The prompt

Act as a test engineer. Write tests for the function below using [TEST_FRAMEWORK]. Before writing code, list: - The behaviours a caller relies on (the contract). - Edge cases: empty, null, boundaries, unicode, large inputs, duplicate values, time zones if relevant. - Failure modes: what should throw or return an error. Then write the tests. Rules: - Test behaviour through the public interface, not private helpers. - One clear assertion focus per test, descriptive test names. - No mocks unless the code does I/O; if it does, mock at the boundary only. - Mark any behaviour that looks like a bug with a comment "POSSIBLE BUG:" and a failing test. Code: [CODE_UNDER_TEST]

Fill in the variables

The prompt above updates live. Nothing leaves your browser.

Remix it

One-click variations. Stack them, then copy.

Open in Prompt Lab →

Why this prompt works

Listing the contract and edge cases first makes the model think about what can break before it writes boilerplate. Banning private-helper tests and over-mocking keeps the suite useful after refactors, and the POSSIBLE BUG marker turns test writing into bug finding.

Framework: Chain-of-Thought. Asks the model to reason through explicit steps before answering.

Example

Illustrative, not a real model output

Example input

[TEST_FRAMEWORK]
Vitest
[CODE_UNDER_TEST]
export function slugify(s) { return s.toLowerCase().replace(/ /g, "-") }

What a good answer looks like (abridged)

Contract: lowercase, spaces become hyphens. Edge cases: multiple spaces, leading/trailing spaces, accents ("Crème Brûlée"), symbols. it("collapses repeated spaces") ... // POSSIBLE BUG: "a b" becomes "a--b" it("strips accents") ... // POSSIBLE BUG: accents are kept

How to use it

  1. Set the TEST_FRAMEWORK variable, paste the CODE_UNDER_TEST, then run the prompt.
  2. First list the contract, edge cases, and failure modes exactly as described.
  3. Write one‑assertion tests using the chosen framework, add "POSSIBLE BUG:" comments where needed.

ChatGPT tips

  • Enclose generated test code in triple backticks so ChatGPT keeps formatting intact.
  • Keep the three sections (contract, edge cases, failure modes) in the exact order for reliable output.

Common mistakes

  • Skipping the contract list and jumping straight to test code.
  • Testing private helpers or over‑mocking internal calls.
  • Omitting edge‑case scenarios or forgetting the POSSIBLE BUG comment.

Guide generated with AI (openai/gpt-oss-120b) on 2026-12-06.

Frequently asked questions

Which AI model works best with the Tests That Actually Catch Regressions prompt?+

It is tuned for ChatGPT and also works in Claude, Gemini, Grok, DeepSeek. Put the output format (schema, table columns) near the top: ChatGPT follows explicit structure very reliably.

How do I use this prompt?+

Copy it, replace the 2 [VARIABLES] (test framework, code under test) with your details, then paste it into ChatGPT. You can fill the variables on this page and copy the finished version.

Is this prompt free to use?+

Yes. Every prompt on Promptnic is free to copy, adapt and use in personal or commercial work. A link back is appreciated, not required.

Why does this prompt work?+

Listing the contract and edge cases first makes the model think about what can break before it writes boilerplate. Banning private-helper tests and over-mocking keeps the suite useful after refactors, and the POSSIBLE BUG marker turns test writing into bug finding.

Related prompts