Flaky tests: the causes, and why retries hide bugs
Flaky tests pass and fail on the same code. The five causes, how each one gives itself away, how to fix it, and why retrying until green hides real bugs.
A flaky test is a test that passes and fails on the same code. Nothing changed, you ran it again, and the answer was different. The usual response is to run it again until it passes. That response is how real bugs reach users with a green report on top.
A flaky test is telling you one of two things. Either the test is sloppy, or the app really does fail some of the time. You can’t know which until you look, and a retry is a way of not looking.
What causes flaky tests

In our experience building a tool that drives browsers all day, the causes fall into five groups. Each one leaves a different fingerprint, which is the useful part: you can usually tell the cause from when it fails, before reading any code.

1. Timing
The test clicks “Create” and checks the page straight away. On a fast day the page has changed. On a slow day it hasn’t yet, and the test reads the old page.
The fingerprint: it fails more on slower machines, in CI more than on your laptop, at busy hours more than at night.
The fix is to wait for the thing you expect, not for an amount of time. “Wait until the heading says Sample item” is right at any speed. “Wait two seconds” is wrong twice: too short on a slow day, wasted on a fast one.
And here is why timing flakes deserve respect. If the page sometimes takes six seconds, your users are waiting six seconds too. The test found something true.
2. Shared data
Two runs use the same account at the same time. One creates an item while the other counts the list. Or yesterday’s leftovers are still there, and today’s “the list has one item” is false before the test begins.
The fingerprint: it fails when runs overlap (two people pushing at once), and it passes when you run it alone.
The fix: every run makes its own data, marks it as its own, and deletes it afterwards. We wrote that up in test data cleanup.
3. Order
Test B passes only if test A ran first and left something behind: a logged-in session, a created item, a dismissed banner. Run B alone, or run the suite in another order, and it fails.
The fingerprint: passes in the suite, fails alone. Or the reverse.
The fix: each test gets itself to its starting point. It logs in, it creates what it needs. Slower, and it means a failure tells you about one test instead of the five after it.
4. Someone else’s service
The test goes through something you don’t run: a payment sandbox, an email provider, a login with another company’s account. When that service is slow or down, your test fails, and your code did nothing wrong.
The fingerprint: failures come in bursts, across several tests at once, and stop by themselves.
There is no real fix, only honesty. The test could not check your app, and it should say that. “Couldn’t check” is a different answer from “broken”, and it should not page anyone at night.
5. Motion
A menu slides open, a banner pushes the page down, an image loads and the button moves. The test clicks where the button was half a second ago.
The fingerprint: the failure says something else was clicked, or nothing happened. It is worse on first load, when nothing is cached.
The fix: wait until the page stops moving before acting. And look at the page yourself. A button that jumps as you reach for it is a real problem for people who use a keyboard, a switch, or an old phone.
Why “retry until green” hides real bugs
Look at the picture at the top again. A feature that fails three runs in ten is failing real people some of the time, and you can’t yet say which people. With automatic retries, the report for that feature is ten green ticks.
That is the whole problem with retries as a habit, and it is one of the ways a test becomes a hollow pass. They treat every flake as the test’s fault, and some flakes are the app’s. A request that sometimes times out, two saves that race each other, a session that sometimes drops: from the outside these all look like “passed on the second try”.
Retries also get worse quietly. One test needs a retry this month. Next quarter it’s many, and the suite is slower for it. Nobody remembers which ones are “known flaky”, and a new failure among them looks like the old noise.
There is one more thing, specific to tests that do real things. If a test sends a real email or places a real test order and then fails, a retry sends it again. For any step that really sends something, a second try is not a harmless repeat.
How to fix flaky tests without hiding them
Make retries visible. If you retry at all, the report must say “passed on the second try”. A pass that needed two attempts is a different fact from a pass.
Give “couldn’t check” its own place. A test that could not reach the form has not found a bug and has not proved the feature. It needs a third answer. We go through the answers a report needs in false positives and false negatives.
Keep the evidence. A screenshot or a recording of the failed attempt, kept even when the retry passed. Most flakes are obvious the moment you watch them, and impossible to guess from a log.
Fix by fingerprint. Note when it fails: alone or in the suite, laptop or CI, in bursts or evenly. Match it against the five causes before opening the code.
Give it a deadline. A flaky test may stay for a week while someone finds the cause. After that it gets fixed or deleted. A test nobody believes is worth less than no test, because it teaches the team that red is normal.
What EveryRole does about it
EveryRole gives a failed test one second try, and never hides that it did: a pass on the second try is shown as passed with the reason saying so. A test that still can’t give a steady answer is set aside as “Couldn’t check”. It is never counted as broken and never counted as passed.
Each run keeps its screenshots and replay. And once a journey has really sent something on your app, there is no second try for that step.
When it suggests a test in the first place, it runs it twice before showing it to you. A test that can’t agree with itself twice in a row is not one you should be asked to trust.


