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 |
|---|---|---|---|
Milliseconds | One function | Local logic regressions | |
Seconds | Two or more modules | Wiring regressions | |
Seconds | One interface | API contract regressions | |
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
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.
Keep changes small
A 5,000-line pull request hides the one line that breaks. A 200-line pull request makes it visible.
Run the full suite, not the touched subset
"It only changed one file" is the sentence that precedes every regression discovered in production.
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
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
Galton, F. (1886). Regression Towards Mediocrity in Hereditary Stature. https://www.jstor.org/stable/2841583
Myers, G. J. (1979). The Art of Software Testing. Wiley. https://www.wiley.com/en-us/The+Art+of+Software+Testing%2C+3rd+Edition-p-9781118031964
Wikipedia (2024). Regression testing. https://en.wikipedia.org/wiki/Regression_testing
Etymology
Origin: borrowed
regression(noun): from Latin regressus, "a going back", from regredi, to return
Semantic network
● broader ● narrower ● related
Used in the garden
Sources
Galton, F. (1886). Regression Towards Mediocrity in Hereditary Stature. https://www.jstor.org/stable/2841583
Myers, G. J. (1979). The Art of Software Testing. Wiley.
Wikipedia (2024). Regression testing. https://en.wikipedia.org/wiki/Regression_testing