On this page
Why flakiness is a leadership problem, not just a testing problem
Flaky tests are expensive in ways that are easy to ignore because the cost is distributed across the entire engineering team. Every rerun costs developer time. Every false failure triggers investigation. Every investigation that finds no defect erodes trust in the CI signal. Over time, teams stop believing test results entirely and fall back on manual verification.
At that point, the automation suite is no longer a force multiplier. It is a tax on throughput. The Oracle release confidence case study shows how a 40 percent reduction in flaky rate directly translated to faster release cycles and higher engineering trust in the pipeline.
Measure the flakiness baseline
Before fixing anything, measure the current state. Most teams do not track flakiness systematically. Start with these four metrics:
- Flaky rate: Percentage of test runs that produce non-deterministic results. Above 5% is critical.
- Rerun burden: How many CI reruns per week are caused by flaky tests.
- False-failure ratio: Of all test failures, what percentage are not real defects.
- Time-to-quarantine: How long a flaky test stays in the active suite before being flagged or removed.
Track these for two weeks before any intervention. The data will reveal which patterns to prioritize. This measurement phase mirrors the diagnose phase of my methodology and is typically the first week of any engagement.
The five root cause categories
Flaky tests almost always fall into one of five categories. Identifying the category tells you which fix strategy to apply.
| Category | Cause | Signal | Fix approach |
|---|---|---|---|
| Timing | Race conditions, async not awaited | Fails intermittently under load | Replace sleep with explicit waits |
| State leakage | Tests share data or session state | Fails only in specific order | Isolate test fixtures |
| Environment drift | Browser version, OS, network variance | Fails in CI but not locally | Standardize environment config |
| Brittle selectors | CSS classes change frequently | Breaks after deployment | Use data-testid attributes |
| Assertion fragility | Over-specified assertions | Fails on minor UI changes | Assert on behavior, not appearance |
For a deeper framework on categorizing and prioritizing automation issues, see QA automation architecture services which covers how to build suites that resist these failure modes from the start.
Triage: fix the biggest blockers first
Not all flaky tests are equal. Prioritize based on impact on release decisions:
- Gate tests that block PR merges. These create immediate friction for every developer. Fix these first even if they are not the most frequently flaky.
- High-signal tests. Tests that catch real defects but also produce false failures. Do not quarantine these — stabilize them.
- Low-signal flaky tests. Tests that rarely catch real defects but fail often. These are candidates for removal or redesign.
- Informational tests. Tests that run but do not influence release decisions. These can be deprioritized until higher-priority items are resolved.
This triage process is a core part of the test automation consulting work I do with engineering teams. Getting the priority order right is often more impactful than the technical fix itself.
The flaky test quarantine workflow
When a test is identified as flaky, follow this automated workflow to prevent it from degrading the CI signal while it is being fixed.
This quarantine workflow ensures that flaky tests do not degrade the CI signal while they are being investigated. The same approach was applied in the Flipkart case study, where a 99 percent test stability rate was achieved through systematic quarantine and root-cause analysis.
Fix patterns with code examples
Here are before-and-after patterns for three common flakiness scenarios. These examples use Playwright syntax, but the patterns apply to any framework.
Pattern 1: Replace implicit timing with explicit waits
// Before: brittle timing hack
await page.waitForTimeout(3000);
const status = await page.locator('.status').textContent();
// After: explicit condition-based wait
await page.waitForSelector('[data-testid="status"]', { state: 'visible' });
const status = await page.getByTestId('status').textContent();
Pattern 2: Isolate test state
// Before: shared state across tests
const user = await createUser();
await page.goto('/dashboard');
// Test A and Test B both use the same user
// After: isolated test fixtures
test('creates dashboard entry', async ({ page }) => {
const user = await createUser({ unique: true });
await page.goto(`/dashboard?userId=${user.id}`);
// State is fully isolated
});
Pattern 3: Robust selectors
// Before: brittle CSS selector
await page.click('.btn-primary.submit-form.ng-scope');
// After: role-based selector
await page.getByRole('button', { name: 'Submit' }).click();
For more detailed Playwright-specific fixes, see how to fix flaky tests in Playwright. For a broader regression strategy, see how to reduce regression bottlenecks.
Prevention: suite health standards
Once the existing flaky tests are stabilized, prevent recurrence with these governance rules:
- Flaky rate SLA: The suite must stay below 3% flaky rate. If it exceeds the threshold for two consecutive sprints, all feature work on tests stops until it is resolved.
- Quarantine policy: Any test that fails without a real defect 3 times in one sprint is automatically quarantined. It cannot return until the root cause is documented and fixed.
- Test review gate: Every new test must pass a code review that checks for timing assumptions, shared state, and selector fragility before it enters the gating suite.
- Ownership: One person owns suite health end-to-end. They are measured on flaky rate and false-failure ratio, not on test count.
What good looks like
A healthy test suite produces reliable green signals that teams trust without manual double-checking. Developers do not ignore failures. Pipelines do not require constant reruns. Release decisions are made based on test results, not despite them. The suite earns its keep by catching real defects early while producing minimal noise.
When your team reaches this state, you are ready to focus on higher-leverage improvements like CI quality gates that improve release confidence and measuring release confidence more broadly.
Get the flaky test audit template
A one-page spreadsheet template to track flaky rate, false-failure ratio, and quarantine decisions across your suite. No email required.
Get the template via email