Overview
A flaky test passes and fails without a relevant code change. Common causes include shared state, timing assumptions, external services, random data collisions and order-dependent setup.
Reproduce before changing
Record the failing test, runtime, seed, environment and logs. Run the test repeatedly and in isolation, then compare behavior when the full suite runs.
Remove uncontrolled inputs
Fix the clock, isolate database records, use deterministic fixtures and replace unreliable network dependencies with controlled test servers or fakes.
Avoid blind retries
Automatic retries can hide defects and make CI appear healthy while the suite remains unreliable. Use retries temporarily for diagnosis, not as the permanent solution.
Track stability
Record flaky tests, assign ownership and measure recurrence. A small, trustworthy suite is more valuable than a large suite that developers routinely ignore.