Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Testing
Testingmedium

What causes flaky tests and how do you fix them?

Tags
#flaky#stability#ci
Back to categoryPractice quiz

Answer

Flaky tests fail nondeterministically due to timing, shared state, or environment issues. Fix them by isolating state, controlling time, waiting for conditions not sleeps, and stabilizing environments.

Advanced answer

Deep dive

Common sources:

  • Race conditions, async not awaited.
  • Shared state between tests.
  • Reliance on external services or clocks.
  • Order-dependent tests.

Fix strategies:

  • Use deterministic clocks and random seeds.
  • Reset state between tests.
  • Replace sleeps with condition-based waits.
  • Quarantine flaky tests and track trends.

Examples

Condition-based wait:

waitUntil(() => element.isVisible())

Common pitfalls

  • Retrying flaky tests without fixing root cause.
  • Ignoring flakes in CI until they pile up.
  • Using real network dependencies in unit tests.

Interview follow-ups

  • How do you detect flaky tests early?
  • When is retry acceptable?
  • How do you keep E2E tests stable?

Related questions

DevOps
Describe the typical stages of a CI pipeline and common failure points.
#ci#pipeline#build
Algorithms
Heap sort: what are its time complexity, space complexity, and stability?
#heapsort#sorting#complexity
Monoliths
How do you approach integration testing in a monolith without making CI
too slow?
#testing#monolith#ci
Algorithms
Counting sort: when can it be faster than O(n log n) sorting?
#counting-sort#sorting#stability
Monoliths
How can you reduce CI/build time in a large monolith/monorepo?
#ci#build#caching