Top 4 Flaky tests Interview Questions
Browse 4 real-world technical and behavioral interview questions about Flaky tests. Review scenarios, edge cases, and architectural best practices.
Your test suite fails randomly about one run in five. How do you get it under control?
Quarantine and measure before fixing: keep per-test pass history so you can rank offenders and restore a trustworthy signal, then work the root-cause families one at a time. Retries belong in a narrow, logged, budgeted policy, because a blanket rerun turns a real product race condition into a green build.
A test passes on its own and fails when the whole suite runs. How do you track that down?
The failing test is a victim, not the cause: something earlier mutated state it shares, usually a module evaluated once, a global that was patched and not restored, or rows left in a database. Bisect the ordering to find the pair, then remove the sharing.
How do you test code that finishes later or depends on the current time, without putting a sleep in the test?
Make time and scheduling injectable. Take a java.time.Clock as a dependency so a test can fix it, and replace a fixed sleep with a bounded poll on the observable outcome, so a fast machine does not wait and a slow one does not fail.
A test passes on your machine and fails in CI roughly once a week. How do you track it down?
Make it reproducible before you make it pass. Pin the ordering seed, then work through the sources of non-determinism the test is exposed to - wall-clock time, global random state, hash-dependent iteration, real network calls and shared resources - and inject each one so the test controls it.