Video in progress
Flaky tests have piled up on your team and developers have gotten used to pressing the "rerun" button. What do you do?
I move the flaky tests to a separate list (quarantine) to make the main pipeline reliable, give each an owner and a deadline, and make retries measurable rather than hidden. The goal is to restore trust in a red build.
📖 Answer
The danger of a "rerun" culture is that a real regression also gets lost in the noise. Once a real race condition is waved through as flaky, it goes to prod.
What I do:
Make it visible. CI should store every test result (JUnit XML → Gradle Develocity, Allure, or a plain table). A test that failed on a commit and passed on rerun is flaky. A weekly list: which tests, how many times.
Quarantine. A flaky test gets @Tag("quarantine") and is taken out of the main job, but keeps running in a separate, non-blocking job. Each has a ticket, an owner and, say, a 2-week deadline. When the deadline passes, it's either fixed or deleted (accepting going without the test as an open decision is better than a hidden flaky one).
Automatic retry, only within a clear limit. Surefire's rerunFailingTestsCount=1 is convenient, but it hides the problem. If I turn it on, tests that passed on retry are marked separately in the report and counted in the statistics.
Classifying the causes. In practice 80% of flaky tests fall into a few groups: sleep and wrong waiting, shared state between tests, time/timezone, random port or order, real calls to the outside network. Write the rule once for each group (Awaitility, Clock, Testcontainers, WireMock), and the errors in later tests go down.
And one simple rule: a PR that adds a new flaky test gets reverted. It sounds harsh, but it changes the culture in a month.
Sign up to mark studied questions and save your progress.