フレーキーテストは、コード変更なしに不安定に合格したり失敗したりするテストです。同じコードでも時には合格し、時には失敗します。テストスイート全体への信頼を損なうため、深刻な問題です。その原因と修正方法を理解することが重要です。
フレーキーテストとは何か、なぜ有害か
A FLAKY test gives INCONSISTENT results (pass sometimes, fail other times) on the SAME code:
→ harmful: ERODES TRUST — people start ignoring failures ("oh, it's just flaky") →
real failures get missed too
→ waste time on false alarms / re-runs; break CI; reduce confidence in the whole suite
→ Flaky tests are worse than no test if they make people distrust all tests.
一般的な原因
✗ TIMING / async → race conditions; not waiting properly for async operations (a top cause
in UI/E2E tests); arbitrary sleeps
✗ ORDER DEPENDENCE → tests depending on each other / shared mutable state
✗ EXTERNAL dependencies → real network/services (network blips, rate limits, downtime)
✗ NON-DETERMINISM → time/dates, randomness, timezone, locale
✗ Test ENVIRONMENT → leftover state, uncleaned data, concurrency/parallelism issues
