Example result: Turn a fixed bug into a regression test
AI-generated example · Regression Test
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.

text-code-bug-to-regression-test — claude — 84 words

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

What you will get

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.

Common mistake

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.

Also watch for
  • 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.
Try a variation: add the edge neighbours

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.

Still not right? Reply with this

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 →