CodeIntermediate

Write the tests that would have caught the bug

Viktor Submitted by Viktor Added 22 days ago
Here's a bug that reached production, and the code around it.

1. Write the failing test that reproduces it at the smallest useful level (unit if the logic is pure, integration if it depends on data or boundaries). Explain that choice.
2. Write the additional tests for the neighbouring cases that are probably also broken — boundaries, empty inputs, nulls, unicode, timezone edges, concurrency, and the largest realistic input.
3. Identify the class of bug this belongs to, then list the other places in the code I pasted that share the pattern.
4. Propose the invariant or type change that makes this bug unrepresentable rather than merely tested.
5. Flag any test you'd advise NOT writing because it would be brittle or test the framework.

Use {{test framework}} and match the existing test style below.

BUG: {{describe}}
CODE: {{paste}}
EXISTING TESTS: {{paste one for style}}

How to use it

Step 4 matters most — if the bug can be made impossible by a type or constraint, the tests are a consolation prize.

Compatible popular AI tools

These tools are mapped to this prompt based on their capabilities.

People who liked this prompt

2 community likes