Regression testing

On this page 7

Regression testing is the practice of re-executing existing tests after a change to confirm that previously working behavior has not been broken. In programming, a regression is any defect where a feature that once passed its tests stops working because of a new commit, a dependency upgrade, a configuration change or a refactoring. Regression testing is therefore not a separate test level but a purpose applied to every level, from unit tests to end-to-end tests.

Within the Testing discipline, regression testing answers one narrow question: did this change break something that used to work? It does not prove that new code is correct; that is the job of the new tests written alongside the change. Its value comes from repetition and automation, because a regression suite runs hundreds or thousands of times over the life of a codebase.

How regression testing detects broken behavior

Regression testing works by comparing current behavior against a recorded baseline. Every test case encodes an expectation that was true when it was written, and a failing test signals that the code no longer meets that expectation. The comparison is only meaningful if the tests are deterministic, meaning the same code and inputs always produce the same result.

In modern teams the process is triggered automatically by continuous integration (CI). A developer pushes a commit, the CI server builds the project, runs the selected regression suite and blocks the merge if any test fails. This short feedback loop of minutes rather than days is what makes regressions cheap to fix, because the offending change is still small and fresh in the author’s mind.

The table below summarizes the stages of a typical automated regression cycle and what each one contributes.

StageWhat happensMain risk if skipped
TriggerCommit, pull request or nightly schedule starts the runRegressions reach the main branch unnoticed
SelectionThe suite or a subset of tests is chosenRuns become too slow or miss affected code
ExecutionTests run against a clean build and fixturesResults depend on leftover state
ComparisonActual results are checked against expectationsSilent behavior changes go undetected
ReportingFailures are linked to the change that caused themDevelopers cannot locate the faulty commit
Stages of an automated regression cycle

Types and scopes of regression testing

Regression testing varies mainly in how much of the suite is executed for a given change. Running everything is the safest option, but large codebases can accumulate suites that take hours, so teams use selection and prioritization strategies to balance confidence against feedback time.

ScopeWhat is executedTypical trigger
Full regressionThe entire automated suite at every levelRelease candidates and nightly builds
Selective regressionTests linked to the changed modulesPull requests in large repositories
Prioritized regressionHigh-risk and historically failing tests firstTime-boxed pipelines
Smoke regressionA small set of critical-path checksEvery deployment to an environment
Visual regressionScreenshot or snapshot comparisonsUser interface and styling changes
Common regression testing scopes

Selective regression relies on test impact analysis, which maps each test to the source files it exercises, usually from coverage data or the build graph. Build tools such as Bazel and several commercial CI services implement this mapping. The technique is powerful but imperfect: changes to configuration files, reflection or shared global state can affect tests that the dependency graph does not connect, so most teams still run a full regression on a fixed schedule as a safety net.

How regression testing relates to other test practices

Regression testing overlaps with many neighboring practices because it describes why a test is run rather than what kind of test it is. The same unit test is a development aid on the day it is written and a regression check on every run afterward. The comparison below clarifies the distinctions that most often cause confusion.

PracticePrimary questionRelation to regression testing
Smoke testDoes the build start and run at all?A minimal, fast subset of regression checks
RetestingIs the reported defect now fixed?Targets one bug; regression checks everything else
Snapshot testingHas the serialized output changed?A technique often used for regression detection
Mutation testingWould the suite catch injected faults?Measures how strong the regression suite is
Acceptance testDoes the feature meet business criteria?Becomes part of the regression suite once passing
Regression testing compared with related practices

The test pyramid also shapes regression strategy. A suite dominated by fast unit and integration tests gives quick regression feedback, while a suite dominated by slow end-to-end tests tends to be run less often, which lets regressions survive longer between detection points.

Building and maintaining an effective regression suite

An effective regression suite is built incrementally from real defects and critical paths. A widely followed rule is that every fixed bug gets a test that reproduces it first and passes after the fix, so the same defect cannot return silently. Over time this practice concentrates coverage where the code has actually proven fragile.

  • Keep tests independent and isolated, using fresh fixtures, mocks or stubs instead of shared databases.
  • Pin dependency versions and test data so that failures reflect code changes, not environmental drift.
  • Track suite duration as a metric and split or parallelize when it grows beyond the agreed budget.
  • Delete or rewrite tests that duplicate others or verify implementation details rather than behavior.
  • Use test coverage to find untested areas, not as a target that guarantees quality.

The decision table below shows how teams typically choose a regression approach for different situations.

SituationRecommended approachReason
Small change in a well-tested moduleSelective regression on the pull requestFast feedback with low risk
Major dependency or framework upgradeFull regression at every levelEffects are broad and hard to predict
Legacy code without testsCharacterization tests before changing itRecords current behavior as the baseline
Hotfix to productionSmoke regression plus targeted testsSpeed matters, but critical paths must hold
Choosing a regression approach

For legacy code, regression testing often starts with characterization tests, which capture what the system currently does, even if that behavior is questionable. They do not assert correctness; they make later refactoring safe by revealing any unintended change.

Limitations and common failure modes

Regression testing can only detect what the suite already checks. A change that breaks an untested path passes every test, so a green pipeline means no known regressions, not no regressions. This limitation explains why teams combine regression suites with code review, monitoring and gradual rollouts.

The most damaging failure mode is the flaky test, which passes and fails intermittently without any code change. Flakiness usually comes from timing assumptions, test-order dependencies, shared state or network calls. When flaky failures become common, developers learn to rerun until green, and genuine regressions start to slip through. Quarantining flaky tests quickly and fixing their root cause is essential to preserving trust in the suite.

A second problem is suite bloat. Suites grow faster than they are pruned, runtimes stretch from minutes to hours, and teams respond by running them less often, which defeats the purpose. Finally, over-specified tests that assert internal details create false regressions on harmless refactorings, adding maintenance cost without catching real defects.

In plain words

Software is like a house where fixing one thing can quietly break another. Replace a light switch and suddenly the doorbell stops working. Regression testing is the habit of checking everything that used to work every time something is changed.

Programmers keep a long list of automatic checks, and a computer runs all of them after each change. If something that passed yesterday fails today, the team knows immediately that the latest change caused it. The key benefit is catching side effects early, while they are still small and easy to fix.

A real-world example

A team maintaining an online booking service with about 4,000 automated tests upgrades its date-handling library to a new major version. The change compiles cleanly, and the new feature it was meant to enable works in manual checks. The pull request triggers the full regression suite, which finishes in 14 minutes across parallel CI workers.

Eleven tests fail, all in the module that calculates cancellation deadlines. The new library interprets daylight saving transitions differently, so bookings made near the clock change would have shown a refund deadline one hour off. Because the failing tests pointed directly at the affected function, a developer adjusted the time zone handling within an afternoon. The regression never reached customers, and the team added two extra tests covering both annual clock changes.