Agile / DevOps · Letter F

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.

By Dr. Hassan Eliwa, PhD · Founder of PMMilestone.org and PMMilestone.com · Updated 2026-08-21

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

  1. Measure it — CI records pass/fail per test per run on identical commits; flake rate is a computed metric, not a feeling.
  2. Set a budget — a visible target (many teams use under 0.5–1% of runs) with the trend on the engineering dashboard.
  3. Detect automatically — retry-once detection flags tests that fail then pass; flagged tests enter the quarantine list with an owner.
  4. Quarantine fast — a flaky test moves out of the blocking path within a day, into a quarantined job that still runs and reports.
  5. Fix or delete on a deadline — quarantine is a hospital with a discharge date, typically one sprint; unfixed tests get deleted or demoted.
  6. 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.
  • Which calculators on PMMilestone.org apply to Flaky Test Management?
    For Flaky Test Management, the most relevant tools on the flagship platform are the EVM, SPI and CPI calculators on PMMilestone.org. They reproduce the formulas referenced in this entry against your own project data.
  • 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.

Related Entries

Browse more in this category

More in Agile / DevOps

View all Agile / DevOps entries →

Further reading on PMMilestone.org

Curated companion resources hosted on the flagship platform, PMMilestone.org.

Related Encyclopedia Entries
Research Articles
Career Guides
Tools on PMMilestone.org
Buy me a coffee