Annotation Type RetryOnException


@Retention(RUNTIME) @Target({METHOD,TYPE}) @Inherited public @interface RetryOnException
Annotation to use with 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");
     }
 }
 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extends Throwable>
     
    int
     
  • Element Details