Flaky tests: find the cause, fix it

Knowledge Videos

Short animated explainers, organised by subject.

Flaky tests: find the cause, fix it

What a flaky test is, the usual causes (fixed sleeps, shared data, fragile locators, timing), how to fix each one, and why retries are a safety net, not a cure.

Transcript

A flaky test passes sometimes and fails sometimes, with the same code and the same app. Flaky tests are worse than no tests, because the team stops trusting a red result.

The common causes: fixed sleeps, tests that share data or depend on each other, fragile locators, and slow servers or animations.

Fix the cause, not the symptom. Replace sleeps with web first assertions. Give each test its own data. Use role and label locators. And wait for the real signal, like a response or a visible message.

Retries can hide the problem. Use them in C I as a safety net, but when the report marks a test as flaky, treat it as a bug to fix, and do not just retry it away.

Remember: a flaky test is a bug in the test. Find the cause, fix it, and use retries only as a safety net.

More in this series