use of org.junit.runner.Computer in project buck by facebook.
the class JUnitRunner method run.
@Override
public void run() throws Throwable {
Level stdOutLogLevel = Level.INFO;
Level stdErrLogLevel = Level.WARNING;
String unparsedStdOutLogLevel = System.getProperty(STD_OUT_LOG_LEVEL_PROPERTY);
String unparsedStdErrLogLevel = System.getProperty(STD_ERR_LOG_LEVEL_PROPERTY);
if (unparsedStdOutLogLevel != null) {
stdOutLogLevel = Level.parse(unparsedStdOutLogLevel);
}
if (unparsedStdErrLogLevel != null) {
stdErrLogLevel = Level.parse(unparsedStdErrLogLevel);
}
for (String className : testClassNames) {
final Class<?> testClass = Class.forName(className);
List<TestResult> results = new ArrayList<>();
RecordingFilter filter = new RecordingFilter();
if (mightBeATestClass(testClass)) {
JUnitCore jUnitCore = new JUnitCore();
Runner suite = new Computer().getSuite(createRunnerBuilder(), new Class<?>[] { testClass });
Request request = Request.runner(suite);
request = request.filterWith(filter);
jUnitCore.addListener(new TestListener(results, stdOutLogLevel, stdErrLogLevel));
jUnitCore.run(request);
}
// Combine the results with the tests we filtered out
List<TestResult> actualResults = combineResults(results, filter.filteredOut);
writeResult(className, actualResults);
}
}
use of org.junit.runner.Computer 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);
}
use of org.junit.runner.Computer in project devonfw-testing by devonfw.
the class TestWatcherExceptionTest method initJUnit.
@BeforeClass
public static void initJUnit() {
BFLogger.logInfo("Starting base test");
computer = new Computer();
jUnitCore = new JUnitCore();
jUnitCore.addListener(new RunListener() {
@Override
public void testFailure(Failure failure) throws Exception {
thrownException = failure.getException();
BFLogger.logInfo("An exception has been thrown: " + thrownException.getMessage());
}
});
}
use of org.junit.runner.Computer in project tutorials by eugenp.
the class Spring5JUnit5ParallelIntegrationTest method givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear.
@Test
void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear() {
final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };
JUnitCore.runClasses(new Computer(), classes);
}
use of org.junit.runner.Computer in project opennms by OpenNMS.
the class GroovyRunnerTest method testCustomJUnitRunnerWithComputer.
@Test
public void testCustomJUnitRunnerWithComputer() throws CompilationFailedException, IOException {
String filename = "src/test/resources/groovy/GroovyRunnerTest.groovy";
Computer computer = new SeleniumComputer("http://www.papajohns.co.uk");
Result result = runJunitTestWithComputer(computer, getGroovyClass(filename));
assertEquals(0, result.getFailureCount());
}
Aggregations