Flaky Test
Question
What is a flaky test and why is it harmful?
Hint
Flaky tests erode trust in the test suite.
Explanation
A flaky test is one that passes and fails intermittently without code changes. Causes: 1) Time-dependent code (Date.now, setTimeout). 2) Shared state between tests. 3) Race conditions. 4) External dependencies (network, filesystem). 5) Random data. 6) Test order dependencies. Harm: 1) Developers ignore failures ("its just flaky"). 2) CI becomes unreliable. 3) Real bugs are missed. 4) Wastes time investigating false failures. Fix: 1) Mock time and randomness. 2) Ensure test isolation. 3) Use deterministic data. 4) Mock external dependencies. 5. Retry in CI (temporary, not a fix). Quaratine flaky tests and fix them promptly.
Related Resources
Related Lessons
- Best Practices
Learn practices.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.