I use JUnit 4.10 to run test suites, and I applied the "retry test" rule after Matthew Farwell's remarks on "How to re-run unsuccessful JUnit tests"? message. I created the "RetryTestRule" class with the following code:
public class RetryTestRule implements TestRule { private final int retryCount; public RetryTestRule(int retryCount) { this.retryCount = retryCount; } @Override public Statement apply(Statement base, Description description) { return statement(base, description); } private Statement statement(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { Throwable caughtThrowable = null;
When using this, as a rule, in a test case it works fine, but it seems impractical to use the @Rule notation in each test case package instead of one notation in the Suite definition, so after checking the bits, I tried the new @ClassRule notation in the Suite class:
@RunWith(Suite.class) @SuiteClasses({ UserRegistrationTest.class, WebLoginTest.class }) public class UserSuite { @ClassRule public static RetryTestRule retry = new RetryTestRule(2); }
The problem is that this does not work properly: failed tests do not repeat. Has anyone tried this and know a solution? Help is much appreciated!
source share