Annotation Interface Repeated


@Retention(RUNTIME) @Target(METHOD) public @interface Repeated
Repeat the annotated test method some number of times

As a matter of practice, no test should ever be committed into source control with this annotation. It is only a tool for diagnosing non-deterministic test failures on the developer's workstation. For example, suppose testSomeMethod fails every other Tuesday on the CI system, but never seems to fail on the developer's workstation. It might help to repeat a test 100 times, including its set-up and tear-down, in a single test run. To do this, the developer can temporarily add the @Repeated(100) annotation, and then run the test from their IDE.

 @Test
 @Repeated(100)
 public void testSomeMethod() {
        SomeClass obj = new SomeClass();
        obj.someMethod();
        assertEquals(3, obj.getSomeState());
 }
 

The number of repetitions can be adjusted depending on the desired level of assurance. If the failure is truly due to timing, and not some other condition unique to the CI system, then it will likely fail within 100 repetitions. Once the code is fixed, and the test passes for the desired number of repetitions, the annotation should be removed before the changes are committed.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    int
    The number of times to repeat the test, must be positive
  • Element Details

    • value

      int value
      The number of times to repeat the test, must be positive
      Returns:
      the count