DevPrep

All topics › Software testing

Why are tests flaky and how do you fix them?

Senior PRO

The gist

A flaky test passes and fails on the same code. It is worse than no test at all: the team gets used to rerunning CI, and a real regression drowns in "it blinked again". The cause is almost always the same — the test depends on something it does not control: run order, real time, the thread scheduler, the network or state left behind by a neighbour. Fix that dependency, not the timeout.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store