# Introducing flaky test mitigation tools

DevFeed: [Introducing flaky test mitigation tools](<https://devfeed.tech/articles/introducing-flaky-test-mitigation-tools-24625.md>)

Original publisher: [Read original article](<https://blog.gradle.org/gradle-flaky-test-retry-plugin>)

Author: Eric Wendelin

Published: 2020-01-13T05:00:00Z

Content type: article

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [ci](<https://devfeed.tech/topics/ci.md>), [Software Engineering](<https://devfeed.tech/topics/software-engineering.md>), [Tooling](<https://devfeed.tech/topics/tooling.md>), [Maven](<https://devfeed.tech/topics/maven.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [ci](<https://devfeed.tech/tags/ci.md>), [flaky](<https://devfeed.tech/tags/flaky.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [gradle-plugin](<https://devfeed.tech/tags/gradle-plugin.md>), [improvements](<https://devfeed.tech/tags/improvements.md>), [pipelines](<https://devfeed.tech/tags/pipelines.md>), [retry](<https://devfeed.tech/tags/retry.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

This article introduces the Test Retry Gradle Plugin and related build scans improvements for mitigating flaky tests. It explains how retrying failed tests can help identify flakiness and describes configuration options for controlling retries, build failure behavior, failure limits, and test granularity.

## Source excerpt

This post introduces a new Gradle plugin and build scans improvements aimed at mitigating your flaky tests. Flaky tests disrupt software development cycles by blocking CI pipelines and causing unnecessary failure investigations. Unhealthy teams live by re-running builds, sometimes several times, to get changes through. Martin Fowler has pointed words about non-deterministic tests that are worth a read. To eliminate this parasite from your organization you have to identify, prioritize, and fix your flaky tests. Mitigating flaky tests There are a number of clever heuristics that help identify flaky tests. You could run some static analysis to prove that a test failure could theoretically not cause a given test failure. You could count the number of "flips" from failed to passed and some threshold that over which a test is considered flaky. These heuristics work, usually, but they are really, really hard to get right. A big problem arises when your flaky test detection methodology is itself flaky -- people do not trust the system and they resolve to rerun-and-suffer mode until they get the result they want. Re-running tests in the same execution environment is a way of identifying a flaky test beyond reasonable doubt. It's no wonder so many teams and libraries incorporate this simple strategy. It's even been built directly into Maven Surefire and Failsafe. This is why we've developed the Test Retry Gradle Plugin that retries failed tests for the purposes of mitigating test flakiness. New Test Retry Gradle Plugin You can use this Gradle configuration to retry tests and optionally fail the build on flakiness: plugins { id 'org.gradle.test-retry' version '1.0.0' } test { retry { failOnPassedAfterRetry = true maxFailures = 42 maxRetries = 1 } } plugins { id("org.gradle.test-retry") version "1.0.0" } tasks.test { retry { failOnPassedAfterRetry.set(true) maxFailures.set(42) maxRetries.set(1) } } There are 4 especially neat aspects to this plugin: No test source changes are re