What are Flaky Tests?

Flaky tests are defined as tests that return both passes and failures despite no changes to the code or the test itself. Several factors can cause unreliable test results, such as inconsistencies in environments, not refreshing test data between test runs, timing and time zone issues, and dependencies on the test execution order.

The problem with flaky tests is that they slow your CI/CD pipeline and erode confidence in testing processes. As you cannot rely on flaky test results, you can’t be sure whether a successful test run means your code is free of bugs or if you should invest time in trying to reproduce and fix an issue when tests fail.

To spot flaky tests, you need to compare test results from multiple test runs. This analysis would be a time-consuming process to perform manually, but fortunately, many CI servers detect flaky tests automatically.

Identifying flaky tests is the first step to getting them under control. Once you know the extent of the problem, you can prioritize fixing them. It’s a good idea to mute flaky tests in the interim so that unreliable test results are excluded from your automated test reports.