@Retention(value=RUNTIME) @Target(value={METHOD,TYPE}) @Inherited public @interface RetryOnException
RetryRule.
Add the RetryRule to your test class and annotate the
class and/or tests with RetryOnException.
@RetryOnException(times=1, exception=IOException.class)
public class YourTest {
@Rule
public RetryRule retryRule = new RetryRule();
@Test
public void yourTest() throws Exception {
// This will be retried 1 time (total runs 2) before failing the test.
throw new IOException("Failing test");
}
@Test
@RetryOnException(times=2, exception=IOException.class)
public void yourTest() throws Exception {
// This will be retried 2 times (total runs 3) before failing the test.
throw new IOException("Failing test");
}
@Test
@RetryOnException(times=1, exception=IOException.class)
public void yourTest() throws Exception {
// This will not be retried, because it throws the wrong exception
throw new IllegalStateException("Failing test");
}
}
Copyright © 2014–2025 The Apache Software Foundation. All rights reserved.