-
-
Save cnevinc/6ed45288960d4df170d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.rules.TestRule; | |
import org.junit.runner.Description; | |
import org.junit.runners.model.Statement; | |
/** Got flaky tests? Shampoo them away. */ | |
public final class ShampooRule implements TestRule { | |
private final int iterations; | |
public ShampooRule(int iterations) { | |
if (iterations < 1) throw new IllegalArgumentException("iterations < 1: " + iterations); | |
this.iterations = iterations; | |
} | |
@Override public Statement apply(final Statement base, Description description) { | |
return new Statement() { | |
@Override public void evaluate() throws Throwable { | |
for (int i = 0; i < iterations; i++) { | |
base.evaluate(); | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment