use of org.junit.runners.model.RunnerBuilder in project buck by facebook.
the class TimeoutTest method doTestUsingThreadGuardedTestClass.
private void doTestUsingThreadGuardedTestClass() throws InitializationError {
Class<?> testClass = ThreadGuardedTest.class;
RunnerBuilder builder = new RunnerBuilder() {
@Override
public Runner runnerForClass(Class<?> clazz) throws Throwable {
return new BuckBlockJUnit4ClassRunner(clazz, /* defaultTestTimeoutMillis */
500);
}
};
Runner suite = new Computer().getSuite(builder, new Class<?>[] { testClass });
Request request = Request.runner(suite);
final Set<Result> results = Sets.newHashSet();
JUnitCore core = new JUnitCore();
core.addListener(new RunListener() {
@Override
public void testRunFinished(Result result) throws Exception {
results.add(result);
}
});
core.run(request);
Result result = Iterables.getOnlyElement(results);
assertEquals(3, result.getRunCount());
assertEquals(2, result.getFailureCount());
// The order in which the tests were run doesn't matter. What matters is that we see our
// expected messages.
Set<String> messages = result.getFailures().stream().map(Failure::getMessage).collect(MoreCollectors.toImmutableSet());
assertEquals("Should contain explicit call to fail() from failingTestsAreReported() and " + "the timeout message from testsMayTimeOut().", ImmutableSet.of("This is expected", "test testsMayTimeOut timed out after 500 milliseconds"), messages);
}
Aggregations