Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.kevinmost:junit-retry-rule:'
}
dependencies {
implementation("com.github.kevinmost:junit-retry-rule:")
}
<dependency>
<groupId>com.github.kevinmost</groupId>
<artifactId>junit-retry-rule</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.kevinmost" % "junit-retry-rule" % ""
:dependencies [[com.github.kevinmost/junit-retry-rule ""]]
A simple @Rule that adds retrying logic to any JUnit 4 tests.
Install via JitPack. Instructions available here
In your test's class, add the RetryRule as a test rule, by creating
an instance of it as a public field, annotated with @Rule.
@Rule public final RetryRule retry = new RetryRule();
Then, for any test that needs to implement retrying logic, annotate
the method with @Retry. Optional parameters on this annotation let
you change defaults such as the number of retries, the timeout length,
etc.
@Test
@Retry(times = 5) // runs test up to 5 times, instead of the default 3 times
public void myFlakyTest throws Exception {
obj.doUnreliableThing();
}
Any test that still fails after its maximum number of tries will throw
a RetryException, which also contains an array of all of the exceptions
that were thrown by each attempt to run this test-case.