---
name: regression-test-for-every-fix
description: "Every defect fix ships a test that fails without the fix. Use when a diagnosed bug is about to be fixed."
---

# Regression Test For Every Fix

**Reproduce before you fix.** Produce a failing automated test that
reproduces the reported defect against unchanged code, and record its
failure output. A reviewer checks that this test existed and failed before
the fix, and returns any fix whose test was written after the code.

**Write the test at the layer where the defect lived.** Produce a unit test
for a wrong calculation. Produce a contract test for a boundary that sent
or accepted the wrong shape. Produce an integration test for a defect that
only appears where two components meet. A reviewer checks that the new test
still fails when the fix is reverted, which proves the layer was right.

**Fix the cause, then widen the test to the class.** Produce two tests for
the defect: one for the exact reported input, and one for a neighbouring
input of the same class that the same cause would break. A reviewer checks
that the fix is not a special case keyed to the reported input, and asks
which sibling inputs share the cause.

**Prove the test fails without the fix.** Produce the revert check: revert
the fix, run the new test, capture the failure, restore the fix. A reviewer
checks that the captured failure is in the change description and that its
message matches the reported symptom.

**Carry the defect identifier into the test.** Produce the issue or ticket
identifier in the test name or its docstring, next to one sentence stating
the observed wrong behaviour. A reviewer checks that a future reader can
reach the original report from the test alone.

**Record the escape.** Produce one line naming which test layer should have
caught this defect and what was missing there. Default: every defect that
reached a released build gets this line [ASSUMPTION]. A reviewer checks
that the line names a layer and a gap, never a person.

**Close nothing on a symptom change.** Produce a behaviour change with a
test, not a log-level edit, a comment, a retry around the failure or a
widened timeout presented as the fix. A reviewer checks that the diff
changes behaviour the new test can observe.

**Keep the regression test forever.** Produce the test in the permanent
suite, not in a scratch file. A reviewer checks that no regression test is
deleted in the same change that touches the code it defends.

**Split a defect that hides two causes.** Produce one test per cause when
reproduction needs two independent conditions. A reviewer checks that each
cause has its own failing test before either fix lands.
