public final class Repeater extends Object implements org.junit.rules.TestRule
RunTimes or RunMaxTimes multiple times.
The rule does not stop on any exceptions, but save them to throw a combined AssertionError at the end of the
evaluation of the Repeater.RepeatStatement. So you will see how many tests failed of how many runs. Also you see the
stack trace of all failures.
Example:
public class TestSomething {
@Rule
public final Repeater repeater = new Repeater();
@Test
@RunTimes(10) // Runs the test method ten times.
public void someTestMethod() {
// ...
}
@Test
@RunMaxTimes(3) // Runs the test method until success, max five times.
public void someOtherTestMethod() {
// ...
}
}
Based on Blog post by Frank Appel.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
Repeater.BaseRepeatStatement
This statement executes the given base statement repeatedly.
|
private static class |
Repeater.RepeatStatement
This statement executes the given base statement repeatedly.
|
private static class |
Repeater.RepeatUntilSuccessStatement
This statement executes the given base statement repeatedly until it succeeds or reaches times.
|
| Constructor and Description |
|---|
Repeater() |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
Description description) |
(package private) boolean |
hasRunMaxTimesAnnotation(Description description)
Whether the description has a
RunMaxTimes annotation or not. |
(package private) boolean |
hasRunTimesAnnotation(Description description)
Whether the description has a
RunTimes annotation or not. |
private void |
validateTimes(int times,
Class<? extends Annotation> annotation)
Validates that the given times value is not less than zero.
|
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, Description description)
apply in interface org.junit.rules.TestRuleprivate void validateTimes(int times,
Class<? extends Annotation> annotation)
This method throws an IllegalArgumentException with an user friendly error message to help test writers
which accidentally used a wrong annotation value.
times - the current annotation valueannotation - the current annotation typeboolean hasRunTimesAnnotation(Description description)
RunTimes annotation or not.description - must not be nulltrue if present, else falseboolean hasRunMaxTimesAnnotation(Description description)
RunMaxTimes annotation or not.description - must not be nulltrue if present, else falseCopyright © 2014 Sven Strittmatter. All Rights Reserved.