Testing interview question · Most asked
Your end-to-end test suite is flaky and takes an hour. How do you fix it?
Scenario Asked in Backend Engineer · QA Engineer / SDET · Frontend Engineer · Full Stack Engineer interviews
Summary
Measure first: which tests fail intermittently and which are slow. Quarantine flaky tests so they don't block merges, fix the root causes (timing waits, shared test data, order dependence, unstable environments), push coverage down to faster API and component tests where possible, and run the remaining end-to-end tests in parallel shards.
Longer Answer
- Flakiness causes: fixed sleeps instead of waiting for conditions, tests sharing accounts or data, reliance on test order, animations, third-party services, timezone and clock issues, under-resourced environments.
- Fixes: explicit waits for state (Playwright auto-waiting,
expect(...).toBeVisible()), unique data per test created through APIs, mocking external services, stable selectors (data-testid, roles). - Speed: delete duplicated end-to-end coverage, test business rules at the API level, set up state through APIs not the UI, shard across machines, run only tests affected by the change on pull requests and the full suite nightly.
- Policy: a flaky-test owner and a deadline; quarantined tests can't stay quarantined forever.
Key Points
- Measure flakiness and duration per test.
- Quarantine, then fix root causes.
- Wait for conditions, never fixed sleeps.
- Push coverage down the pyramid; shard the rest.
Explanation
What interviewers look for
Diagnosing the real causes of flakiness and restructuring the suite, not just adding retries.
More Testing questions
- What's the difference between mocks, stubs, fakes and spies?
- What causes flaky tests and how do you fix them?
- What is the test pyramid, and is it still relevant?
- What makes a good unit test?
- Write a Playwright test that logs in and checks the dashboard, and explain how you keep it stable.
- How do you write reliable integration tests that use a database?
- How would you design a test strategy for a new web application?
- A critical bug reached production even though all tests passed. What do you do?