A flaky test gives different results on the same code: green on the first run, red on the second. The most common causes are fixed waits, data shared between tests, execution order, the network or a clock.
The real cost isn’t the time lost rerunning it: it’s trust. When the team gets used to rerunning a red test, it ends up ignoring a real bug.
How to deal with it
- Measure: track each test’s failure rate over the last 30 days.
- Isolate: put the test in a visible quarantine, with a ticket and an owner.
- Fix the cause: wait for a state rather than a duration, isolate the data, mock external services.