Skip to content

Regression

A regression is a defect that reintroduces previously fixed behaviour or degrades existing functionality after a change; the term comes from Francis Galton (1886), who observed that extreme traits revert toward the mean across generations.

Definition

What it is

A regression is not a bug in new code. It is a bug in old code, caused by new code. The feature worked before the change, and does not work after. The cause is often an unexpected coupling: a shared utility that was modified, a global that was reassigned, a database index that was dropped during a migration, a dependency that was upgraded.

The word also has a non-defect sense: a regression test is a test whose purpose is to detect such defects. The test asserts that a specific behaviour continues to hold after changes. It is written once, ideally before the code it protects, and runs forever.

Why it matters

A codebase without regression tests is a codebase where every change is a gamble. The change looks local, but the behaviour it breaks was global. The cost compounds: the feature that broke is usually the one nobody was watching, because everybody was watching the new one.

Regressions are statistical, too

In the 1880s, Francis Galton was studying heredity. He noticed that the children of tall parents were, on average, shorter than their parents; the children of short parents were, on average, taller. He called the phenomenon regression toward mediocrity, and later regression toward the mean. The word regression entered statistics through his work.

From statistics it passed to quality control in the mid-20th century: a process that had been stabilised could regress to its previous unstable state. Software testing adopted the term in the 1970s and 1980s, with the growth of structured methodologies and automated testing tools. The sense survives: something that had been fixed reverts.

The regression test pyramid

Level

Speed

Coverage

Detects

Unit test

Milliseconds

One function

Local logic regressions

Integration test

Seconds

Two or more modules

Wiring regressions

Contract test

Seconds

One interface

API contract regressions

End-to-end test

Minutes

Whole system

User-flow regressions

Canary in production

Minutes

Real traffic

Behavioural regressions at scale

Where regressions come from

graph TD
  R[Regression] --> S[Shared utility changed]
  R --> D[Dependency upgraded]
  R --> M[Migration script]
  R --> C[Global state mutated]
  R --> P[Public API changed]
  style R fill:#FFEBEE

How to prevent one

Preventing regressions

  1. Write the test first

    If the test does not exist, the feature has no contract. A regression test written before the code is a contract the code cannot break silently.

  2. Keep changes small

    A 5,000-line pull request hides the one line that breaks. A 200-line pull request makes it visible.

  3. Run the full suite, not the touched subset

    "It only changed one file" is the sentence that precedes every regression discovered in production.

  4. Never trust a test that has never failed

    A test that has never failed has never proven it can fail. Break the code on purpose, once, and confirm the test goes red.

Origin

The offspring of the shorter parents are, on the average, taller than their parents; and the offspring of the taller parents are, on the average, shorter.

— Francis Galton, *Regression Towards Mediocrity in Hereditary Stature*, 1886
1886 · publicación del paper de Galton
1979 · *The Art of Software Testing* de Myers formaliza la idea
1999 · JUnit populariza la regression suite automatizada
2011 · Selenium 2.0 masifica los e2e como suite de regresión
2020 · Playwright entra al mercado y afianza el modelo

Evidence

FAQ

Regression vs bug?

A bug is a mismatch between code and spec. A regression is a bug that did not exist before a change. All regressions are bugs; not all bugs are regressions.

When to write a regression test?

After every reported bug, before the fix. The test asserts the bug cannot return.

How many regression tests?

Enough to cover every path that has ever been fixed. If a bug was fixed once, a test must exist to prove it stays fixed.

Are end-to-end tests regression tests?

They can be, but a suite of only e2e tests is slow and fragile. Distribute regressions across the pyramid.

Connections

Etymology

Origin: borrowed

  • regression (noun): from Latin regressus, "a going back", from regredi, to return

Semantic network

Regressionsoftware-tsoftware-qSmoke testStubMockFixtureContinuous

● broader ● narrower ● related

Broader

  • software-testing
  • software-quality

Related

Used in the garden

Sources