Write the test that would have caught it

by Leumas · for any

  • code
  • testing
  • regression
I just fixed this bug:

<bug>
[WHAT WAS WRONG]
</bug>

<fix>
[THE DIFF]
</fix>

Write the test that would have caught it.

Requirements:
- It must FAIL on the code before the fix and PASS after. Say explicitly which line of the old code makes it fail.
- Test the behaviour, not the implementation — it should survive a reasonable refactor.
- Use the conventions already in the test files I have shown you. If I have shown none, ask before choosing a framework.
- One test for the bug. Then list, without writing them, any adjacent cases the same fix should have covered.

What it is for

Written for the moment just after a bug is fixed, when the fix is obvious and the test is not. The "fails on the old code" clause is the whole point — a test that passes either way proves nothing.

0 reads. Free to copy and to use — nothing here runs your prompt, so there is nothing to pay for.