
- Updated
Turn a fixed bug into a regression test
Once a bug is fixed, a regression test makes sure it stays fixed. This prompt writes a small test named after the behaviour, which fails on the old code and passes on the new code.
Act as a careful engineer. Bug that happened: [WHAT WENT WRONG, e.g. total showed ₹0 when cart had one free item] How it was fixed: [PASTE THE FIX OR DIFF] Test framework: [e.g. pytest] Write a regression test that fails on the old code and passes on the fixed code. Name it after the behaviour, not the ticket number. Keep it small and focused on this bug, and add a one-line comment linking the test to the bug so nobody deletes it by mistake.
To be sure the test works, undo the fix for a moment and check the test fails.
Get a better result
A small, focused regression test, named after the behaviour, that fails on the old code and passes on the fix, with a one-line comment linking it to the bug.
The test passes on the old code as well.
Fix: Revert the fix, run the test, and check that it fails for the right reason. If not, ask the AI to match the exact input from the bug.
- The test is large and checks many things. Ask for one scenario and one main assertion, with only the setup needed to trigger the bug.
- The name refers to a ticket number. Name it for what should happen, such as “free item keeps the total at zero”. The name should explain a failure to a stranger.
Ask for “two more tests for the nearest edge cases, such as an empty cart and two free items”. Bugs often have close relatives that fail in the same area.
Make this test smaller. Use the exact values from the bug report, remove any setup not needed and keep the single assertion.
Guides on this topic
More chat & writing prompts
See all 465 →More like this
- Fix a bug that works locally but fails in productionClaude · ChatGPT · Gemini
- Write a clear bug reportChatGPT · Gemini · Claude
- Let an AI agent fix failing tests properlyClaude Code · Cursor
- Write unit tests for your codeClaude · ChatGPT · Gemini
- Convert code from one language to anotherChatGPT · Gemini · Claude



