@Retention(value=RUNTIME) @Target(value=METHOD) public @interface RunMaxTimes
What is the use case of this stuff?
Imagine a test which only fails some times because of a timing issue. E.g. you have UI tests which are almost always fine and green, but... Some times the UI test machine is under heavy load and on UI widget occurs a nanosecond too late and the test fails. This leads to test erosion and everybody will ignore the test failures because in the next run the test will be green. The real defect is discovered days too late...
For issues like that this rule gives the possibility to say: Hey, if that test fail, then give it a next chance. Maybe it is green on the next run. \this rule will execute a test at least once, but if it fails repeats the execution until it passes or the maximum is reached (if a test fails five times or so in sequence, then it is maybe a real defect).
Use this annotation together with the repeater rule.
Example with default maximum value:
@Test
@RepeatUntilSuccess // Max. five times.
public void someTestMethod() {
// ...
}
Example with custom maximum value:
@RunMaxTimes(3) // Max. three times.
public void someOtherTestMethod() {
// ...
}
Repeater| Modifier and Type | Fields and Description |
|---|---|
static int |
DEFAULT_MAX_TIMES
Default value for maximum executions.
|
| Modifier and Type | Optional Element and Description |
|---|---|
int |
value
How many times a test should be executed at maximum if it fails.
|
public static final int DEFAULT_MAX_TIMES
public abstract int value
Must return an int greater than 0 , defaults to DEFAULT_MAX_TIMES.
Copyright © 2014 Sven Strittmatter. All Rights Reserved.