Testing interview question · Most asked

What causes flaky tests and how do you fix them?

Summary

Flaky tests pass and fail without code changes. Common causes: timing and race conditions, shared state between tests, test order dependence, real network or time dependencies, randomness, and resource limits in CI.

Longer Answer

Fixes: wait for conditions instead of sleeping, isolate data, freeze time and seed randomness, mock external networks, and run tests in random order locally to catch dependencies. Track flakiness and treat it as a bug; automatic retries hide real problems.

Key Points

  • Timing/race conditions
  • Shared state and order dependence
  • Uncontrolled time/network/randomness
  • Track and fix; don't just retry

More most-asked Testing questions

← All Testing questions