Class RunUntilFailureRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class RunUntilFailureRule
    extends Object
    implements org.junit.rules.TestRule
    JUnit Rule which allows to keep running tests indefinitely.

    This is useful to add locally, never commit, if you would like to keep running a "flaky" (sometimes passing, sometimes failing) test until it fails. Usage:

       public static @ClassRule RunUntilFailureClassRule classRepeater = new RunUntilFailureClassRule();
       public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
    
       @Test ...

    The two rules are necessary because a ClassRule alone cannot stop the test on a failure, and a normal Rule alone cannot keep running all @Test (it would indefinitely run only the first test). Alternatives to two rules would be to use a @RunWith with a custom TestRunner, or writing a test suite each time.

    Author:
    Michael Vorburger
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement statement,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule