Skip to content

Regression

In one line

A regression is when code that used to work stops working after a change. Tests exist to catch regressions.

In simple words

A regression is a bug that introduces a failure in functionality that previously worked. You change code for one reason, and accidentally break something else — that's a regression.

Regressions are the primary enemy that testing fights. Without tests, you might change a function and unknowingly break another function that depends on it. The bug might not surface until a user encounters it in production.

With tests, regressions are caught immediately. When you change code and run the test suite, any test that was passing before and now fails indicates a regression. You know right away what you broke and can fix it before the code reaches production.

This is why we say tests 'catch regressions' — they prevent previously working behavior from breaking. A regression test is specifically a test written to verify that a previously fixed bug doesn't reappear.

Example

javascript
// Regression test — ensures a fixed bug stays fixed

// Bug: abs() returned wrong value for zero
// Fix commit: "fix: abs(0) should return 0"

test('regression: abs(0) returns 0 (bug #42)', () => {
  expect(abs(0)).toBe(0);  // This test prevents bug #42 from returning
});

// Run the full suite after any change:
// $ npm test
//  ✓ regression: abs(0) returns 0 (bug #42)
//  152 passing
// If someone reintroduces the bug, this test fails immediately.

A regression test locks in a previously fixed bug so it can't come back. The test references the bug number and verifies the fix; if someone reintroduces the bug, the test fails immediately.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary