Search in sources :

Example 1 with Computer

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);
    }
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) Computer(org.junit.runner.Computer) Request(org.junit.runner.Request) Level(java.util.logging.Level)

Example 2 with Computer

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);
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener) RunnerBuilder(org.junit.runners.model.RunnerBuilder) Computer(org.junit.runner.Computer)

Example 3 with Computer

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());
        }
    });
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Computer(org.junit.runner.Computer) Failure(org.junit.runner.notification.Failure) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException) RunListener(org.junit.runner.notification.RunListener) BeforeClass(org.junit.BeforeClass)

Example 4 with Computer

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);
}
Also used : Computer(org.junit.runner.Computer) ParallelComputer(org.junit.experimental.ParallelComputer) Test(org.junit.jupiter.api.Test) Example2IntegrationTest(com.baeldung.Example2IntegrationTest) Example1IntegrationTest(com.baeldung.Example1IntegrationTest)

Example 5 with Computer

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());
}
Also used : SeleniumComputer(org.opennms.netmgt.junit.runner.SeleniumComputer) Computer(org.junit.runner.Computer) SeleniumComputer(org.opennms.netmgt.junit.runner.SeleniumComputer) Result(org.junit.runner.Result) Test(org.junit.Test)

Aggregations

Computer (org.junit.runner.Computer)6 JUnitCore (org.junit.runner.JUnitCore)3 Test (org.junit.Test)2 ParallelComputer (org.junit.experimental.ParallelComputer)2 Request (org.junit.runner.Request)2 Result (org.junit.runner.Result)2 Runner (org.junit.runner.Runner)2 RunListener (org.junit.runner.notification.RunListener)2 Example1IntegrationTest (com.baeldung.Example1IntegrationTest)1 Example2IntegrationTest (com.baeldung.Example2IntegrationTest)1 BFInputDataException (com.capgemini.ntc.test.core.exceptions.BFInputDataException)1 ArrayList (java.util.ArrayList)1 Level (java.util.logging.Level)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.jupiter.api.Test)1 Failure (org.junit.runner.notification.Failure)1 RunnerBuilder (org.junit.runners.model.RunnerBuilder)1 SeleniumComputer (org.opennms.netmgt.junit.runner.SeleniumComputer)1