Write the tests that would have caught this
Turns a bug you just fixed into the regression test you should have had.
A bug reached production. Write the tests that would have stopped it. The bug: [WHAT WENT WRONG] The fix: ``` [PASTE THE FIX] ``` Produce, using [TEST FRAMEWORK]: 1. **The regression test** — fails on the old code, passes on the new. This one matters most; make it obvious from the test name what broke. 2. **The neighbours** — two or three cases near the same boundary that are probably also wrong and nobody has checked. 3. **One honest note** on what still is not covered and would need a different kind of test. Table-driven where the cases are variations on one input. Do not test the framework, do not assert on private internals, and do not write a test that would pass against a function that returns a hard-coded value.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
The bug: The shop page says "free shipping from 50". An order of exactly 50.00 was charged 4.95 for shipping.
The fix
--- a/shipping.py
+++ b/shipping.py
@@ -1,4 +1,4 @@
def shipping_cost(subtotal):
- if subtotal > 50:
+ if subtotal >= 50:
return 0
return 4.95
Test framework: unittest, from the Python standard library
Example output
import unittest
from shipping import shipping_cost
class ShippingTest(unittest.TestCase):
def test_exactly_50_ships_free(self):
self.assertEqual(shipping_cost(50), 0)
def test_one_cent_either_side(self):
cases = [(49.99, 4.95), (50.01, 0)]
for subtotal, expected in cases:
with self.subTest(subtotal=subtotal):
self.assertEqual(shipping_cost(subtotal), expected)
if __name__ == "__main__":
unittest.main()
1. The regression test is test_exactly_50_ships_free. On the old code it fails with 4.95 != 0. On the fix it passes.
2. The neighbours are 49.99 and 50.01, one cent either side of the threshold. Both pass on the old code and on the fix. They pin the two sides, so the next edit to the comparison cannot move either one unnoticed.
3. What is still not covered. shipping_cost receives a subtotal that some other code added up. As floats, 16.70 + 16.65 + 16.65 is 49.99999999999999, so a basket with those three prices still pays 4.95 after the fix. The same prices in the order 16.65, 16.65, 16.70 add up to 50.0 and ship free. No test of this function can catch that. It needs a test one level up, where the basket adds its line items, and it is a reason to hold prices in cents.
More Coding prompts
3 of the 7 other prompts filed under Coding.
Explain this code to me at the depth I ask for
Paste the code and pick one paragraph or a full walkthrough. You get what it does, why it might be written that way and what to watch for.
Find the bug from a stack trace
Works backwards from an error to a specific line and a specific cause.
Plan a refactor before touching anything
Turns a vague urge to clean something up into an ordered, revertible sequence.
Coding tools and skills
3 of the 9 tools and 3 of the 7 skills filed under Coding, the same category as this prompt.
Continue
Open-source coding agent for VS Code, JetBrains and the CLI. Cursor acquired it, and the repository is read-only.
Cursor
An editor built around AI-assisted editing.
Devin Desktop
A full IDE with a command center for running local and cloud coding agents. It used to be called Windsurf.
Accessibility reviewer
Reviews a component against WCAG failures that automated tools miss.
API endpoint reviewer
Checks a handler for the auth, validation and error gaps that recur.
Code reviewer
Reviews a diff for defects, and refuses to pad the list with style opinions.
Coding guides
3 of the 6 guides filed under Coding, the same category as this prompt.
Reviewing code an AI wrote
It compiles, the tests pass, and it reads well. That combination is exactly why it needs a different kind of review.
Claude Code alternatives: agentic coding tools compared
What Claude Code needs from you today, which agents replace it in the terminal, in an editor, on your own models or in the cloud, and which of them read your SKILL.md files.
GitHub Copilot alternatives: AI coding assistants compared
What Copilot Free covers today, which tools on this index replace it in your editor, in the terminal, on your own models or across a large codebase, and the catch of each.