Flaky Test Management
The discipline of measuring, quarantining and fixing tests that pass and fail without any code change — before the team learns to ignore red builds and ships a real regression past them.
Definition
A flaky test is one that produces different results on identical code — green on one run, red on the next, pass on retry. Flaky test management is the operational discipline around them: measuring flake rate per test and per suite, quarantining offenders fast, assigning owners with a fix deadline, and deleting tests that cannot justify their upkeep. It treats the test suite as production infrastructure, because that is what it is — the quality gate every change passes through.
Why It Matters
Flakiness is corrosive in a way that is easy to miss. One flaky test teaches engineers to click "re-run." Five teach them to assume red means infrastructure. At that point the suite's alarm value is gone — a real regression lands, the build goes red, and everyone waits for it to go green by itself. This is how teams with thousands of tests ship broken checkouts. The flake rate is therefore a leading indicator of delivery risk: when it climbs, trust in the pipeline is already falling, and the real failure is only a matter of time.
How the Discipline Works
- Measure it — CI records pass/fail per test per run on identical commits; flake rate is a computed metric, not a feeling.
- Set a budget — a visible target (many teams use under 0.5–1% of runs) with the trend on the engineering dashboard.
- Detect automatically — retry-once detection flags tests that fail then pass; flagged tests enter the quarantine list with an owner.
- Quarantine fast — a flaky test moves out of the blocking path within a day, into a quarantined job that still runs and reports.
- Fix or delete on a deadline — quarantine is a hospital with a discharge date, typically one sprint; unfixed tests get deleted or demoted.
- Fix the causes, not the symptoms — the recurring offenders: sleeps, time-dependence, shared state, order-dependence, real network and filesystem calls.
Real-World Example
An e-commerce team's checkout suite had drifted to a 4% flake rate. Red builds were routinely re-run twice and merged on the third attempt; "known flaky" was a standing phrase in review comments. Then a genuine payment-routing regression turned the build red, was re-run, went green on an unrelated retry, and shipped — £40,000 in duplicated charges and a painful customer-remediation exercise. The recovery was systematic: flake rate measured per test, a 0.5% budget, automatic quarantine with a one-sprint fix deadline, and a rule that retry counts are reported, never hidden. Three months later the suite ran at 0.3%, red builds were treated as guilty until proven innocent, and the phrase "known flaky" disappeared from the team's vocabulary — because the list it referred to was empty.
Practical Lessons Learned
- Retries hide, they do not heal. Auto-retrying a failed test until it passes converts signal into silence; report the retry rate instead.
- Sleeps are the gateway drug. A fixed
sleep(500)is a race condition with a lucky number; wait on conditions, never on clocks. - Time-bombs ship in January and detonate in February. Tests that depend on wall-clock dates, time zones or locale formats fail on a schedule, not on a change.
- Shared state makes order-dependence. A test that passes alone and fails in the suite is reading something another test wrote — isolate with fresh fixtures, not bigger timeouts.
- Quarantine without a deadline is a graveyard. Every quarantined test needs an owner and a discharge date on the day it is admitted.
Expert Tips
- Run the suite repeatedly on an unchanged commit nightly; anything that flips is flaky by construction, with no debate about whether the code changed.
- Track flake rate per team and per test, and publish the worst offenders — ownership follows visibility remarkably fast.
- Prefer fewer, stronger assertions: a test that checks one behaviour clearly is fixable; a 40-assertion end-to-end script is usually deleted, mourned by no one.
- When a test flakes, capture the environment snapshot — seed, clock, dependency versions — before re-running; flakes debugged from logs after the fact take five times longer.
- Count deletion as a valid fix. A test that asserts nothing meaningful, costs a week a year in re-runs, and flakes monthly is negative value.
Common Mistakes
- Annotating tests with automatic retries as policy, so the suite reports green while the retry metric quietly doubles.
- Quarantining forever — a list of 200 "temporarily" skipped tests that no one has looked at in a year.
- Blaming CI infrastructure for every flake without data; some flakes are the runner, but most are timing and state bugs in the tests themselves.
- Fixing flakes by increasing timeouts, which turns a 10-second suite into a 40-minute one and changes nothing about the race.
- Treating flake fixes as unscheduled charity work, so they always lose to feature tickets until the day the suite's alarm value is gone.
Key Takeaways
- Flaky tests destroy the suite's alarm value; the flake rate is a delivery-risk metric, not an annoyance.
- Measure per test, set a budget, and put the trend where engineering reviews happen.
- Quarantine fast with an owner and a discharge date — hospital, not graveyard.
- Fix causes: condition-based waits, frozen clocks, isolated fixtures, no real network.
- Report retries, never hide them — and count deletion as a legitimate cure.
Related Concepts
Pairs with Continuous Integration, Test-Driven Development, Quality Gate, and Trunk-Based Development.
Frequently Asked Questions
What flake rate should a team tolerate?
Most healthy teams aim under 0.5 to 1% of test runs. The absolute number matters less than the direction and the response: a visible trend, automatic detection, and quarantine within a day. Above a few percent, engineers stop believing red builds — and restoring that belief afterwards costs far more than the fixes would have.Should CI automatically retry failed tests?
Retries are legitimate as a detection mechanism — run once more to see if the failure is stable — but never as a silencer. The common mistake is merging on the retry pass with no record. Report every retry as a flake event; if a test needs three attempts to go green, that is a measurement, not a success.What are the most common causes of flakiness?
In order of frequency on most suites: fixed sleeps instead of condition waits, dependence on wall-clock time or time zones, shared state between tests causing order-dependence, real network or filesystem calls, and resource contention on shared CI runners. The fixes are structural — freeze the clock, isolate fixtures, fake the network.Isn't deleting a flaky test just lowering coverage?
Coverage of what? A test that fails randomly asserts nothing reliably and costs re-runs, attention and trust. Deleting it — or better, replacing it with a smaller deterministic test of the same behaviour — raises the suite's real value. Coverage percentages that count unreliable tests are vanity metrics.Who should fix flaky tests?
The team that owns the behaviour under test, assigned automatically when the flake is detected, with a one-sprint deadline. Central QA fix-it squads fail because the context lives with the owning team — and because without ownership, quarantine becomes the graveyard it is meant to prevent.How do I debug a flake that only fails on CI?
Reproduce the environment before re-running: capture the random seed, system clock, dependency lockfile and runner spec on failure. Then run the test in a loop locally under matching conditions — most CI-only flakes are timing races that a slower, busier runner exposes. Increase logging on the first failure, not after the re-run has wiped the evidence.What is a common misconception about Flaky Test Management?
That the topic is well-defined across all references. In practice, definitions vary between PMBOK, PRINCE2, AACE and ISO 21500 — this entry uses the definition most aligned with field practice on capital projects, and flags where the standards diverge.Which related encyclopedia entries should I read alongside Flaky Test Management?
Read Earned Value Management, Critical Path Method and the DCMA 14-point assessment next. The full A–Z is available in the PMMilestone Encyclopedia, and quick one-line definitions live in the PM Glossary on the flagship platform.How does Dr. Hassan Eliwa's research treat Flaky Test Management?
Dr. Hassan Eliwa's research focuses on owner-side project controls, schedule integrity and forensic delay analysis on capital construction and power programmes. Flaky Test Management is treated through that lens — what a planning or controls engineer is expected to do with it on a live project, not its textbook definition alone. See the full research library at PMMilestone Research Articles.How is Flaky Test Management defined on PMMilestone Research & Insights?
The discipline of measuring, quarantining and fixing tests that pass and fail without any code change — before the team learns to ignore red builds and ships a real regression past them. For the full treatment, see the definition, principles, applications and related entries above — every encyclopedia entry follows the same research-grade structure.
People also ask
Follow-up questions practitioners search for next — each one points to the calculator, template or reference entry that answers it.
Which learning track covers this end-to-end?
Structured tracks from beginner planner to programme controls director. Project Controls Academy ↗
Which book goes deeper than this entry?
Practitioner field handbooks with worked numerical examples. Books & Publications ↗
Which calculator on PMMilestone.org applies here?
The integrated EVM workbook covers most cost-schedule diagnostics. EVM Calculator ↗
Where is this in the glossary?
Quick-lookup definitions across 1,200+ PM terms. PM Glossary on PMMilestone.org ↗
Related Entries
More in Agile / DevOps
- Letter BBug Triage
The regular, disciplined meeting where new defects are reviewed, classified, prioritised and assigned — the difference between a live product backlog and a graveyard of unresolved tickets.
- Letter DDependency Upgrade Cadence
The habit of upgrading libraries and frameworks in small, continuous, bot-assisted steps — so security patches land in days and the dreaded 'big-bang upgrade' never has to happen.
- Letter DDeployment Freeze Window
A pre-agreed period during which no non-emergency changes reach production — the operational discipline that protects a business's most exposed hours from avoidable engineering risk.
- Letter IInfrastructure as Code (IaC)
The practice of provisioning and managing servers, networks, databases and cloud resources through version-controlled definitions rather than manual clicks in a console.
- Letter RRollback Plan
The pre-agreed, tested sequence for reverting a change if it fails in production — the difference between a five-minute recovery and a five-hour outage.
- Letter ZZero-Downtime Migration
The set of patterns that move a live system from an old state to a new one — database, service, provider or region — without an outage window, using dual writes, shadow reads, and staged cutovers.
Further reading on PMMilestone.org
Curated companion resources hosted on the flagship platform, PMMilestone.org.
- For practitioners who want to go deeper, the Learning Tracks.
- Engineers researching this topic typically continue with the Books & Publications.
- A practical companion to this entry is the EVM Calculator.
- Closely related on the flagship platform is the PMMilestone.org knowledge hub.