A regression test checks that something that used to work still works after a change. The name comes from software “regressing”: a bug you already fixed, or a feature that was fine, quietly breaks again. A regression test stands guard so that it cannot happen unnoticed.

What makes a good regression test

  • Born from a bug — write the test first so it fails because of the bug, then fix the bug and watch it pass.
  • Kept forever — it stays in the suite, so the same problem cannot return unnoticed.
  • Automatic — run it on every change in continuous integration, not just when someone remembers.
  • Specific — check the exact behavior that broke, not everything around it, so a failure points at the cause.

The shape of a regression test

It is usually a small, ordinary test whose name or comment records the bug it protects against.

// Regression test for bug #123: a 100% discount used to give a negative total.
test('a 100% discount gives a total of zero', () => {
  const total = checkout({ price: 20, discount: 1 });

  expect(total).toBe(0);
});

Run regression tests on every change with continuous integration.