Search in sources :

Example 1 with RunListener

use of org.junit.runner.notification.RunListener in project mockito by mockito.

the class ConsoleSpammingMockitoJUnitRunner method run.

@Override
public void run(RunNotifier notifier) {
    RunListener listener = new RunListener() {

        WarningsCollector warningsCollector;

        @Override
        public void testStarted(Description description) throws Exception {
            warningsCollector = new WarningsCollector();
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            logger.log(warningsCollector.getWarnings());
        }
    };
    notifier.addListener(listener);
    runner.run(notifier);
}
Also used : Description(org.junit.runner.Description) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 2 with RunListener

use of org.junit.runner.notification.RunListener in project mockito by mockito.

the class VerboseMockitoJUnitRunner method run.

@Override
public void run(RunNotifier notifier) {
    //a listener that changes the failure's exception in a very hacky way...
    RunListener listener = new RunListener() {

        WarningsCollector warningsCollector;

        @Override
        public void testStarted(Description description) throws Exception {
            warningsCollector = new WarningsCollector();
        }

        @Override
        @SuppressWarnings("deprecation")
        public void testFailure(final Failure failure) throws Exception {
            String warnings = warningsCollector.getWarnings();
            new JUnitFailureHacker().appendWarnings(failure, warnings);
        }
    };
    notifier.addFirstListener(listener);
    runner.run(notifier);
}
Also used : Description(org.junit.runner.Description) JUnitFailureHacker(org.mockito.internal.junit.util.JUnitFailureHacker) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 3 with RunListener

use of org.junit.runner.notification.RunListener in project jena by apache.

the class DBTest method execCmd.

@Override
protected void execCmd(List<String> args) {
    if (isVerbose()) {
        for (String k : params) System.out.printf("%-20s = %-20s\n", k, params.get(k));
        System.out.println();
    }
    Connection jdbc = getModStore().getConnection().getSqlConnection();
    // Hack to pass to calculated parameters to the test subsystem.
    sdb.test.Env.set(jdbc, params, false);
    JUnitCore x = new org.junit.runner.JUnitCore();
    //RunListener listener = new TextListener2() ;
    RunListener listener = new TextListener2(System.out);
    x.addListener(listener);
    //x.run(sdb.test.AllTests.class) ;
    System.out.println("String basic");
    x.run(TestStringBasic.class);
    System.out.println("String I18N");
    x.run(TestI18N.class);
// Better way of having parameters for a class than a @Parameterised test of one thing?
//        Request request = Request.aClass(sdb.test.T.class) ;
//        x.run(request) ;
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Connection(java.sql.Connection) TextListener2(sdb.junit.TextListener2) RunListener(org.junit.runner.notification.RunListener)

Example 4 with RunListener

use of org.junit.runner.notification.RunListener in project bazel by bazelbuild.

the class JUnit4Runner method run.

/**
   * Runs the JUnit4 test.
   *
   * @return Result of running the test
   */
public Result run() {
    testRunnerOut.println("JUnit4 Test Runner");
    checkJUnitRunnerApiVersion();
    for (Initializer init : initializers) {
        init.initialize();
    }
    // Sharding
    TestSuiteModel model = modelSupplier.get();
    Filter shardingFilter = model.getShardingFilter();
    Request filteredRequest = applyFilters(request, shardingFilter, config.getTestIncludeFilterRegexp(), config.getTestExcludeFilterRegexp());
    JUnitCore core = new JUnitCore();
    for (RunListener runListener : runListeners) {
        core.addListener(runListener);
    }
    File exitFile = getExitFile();
    exitFileActive(exitFile);
    try {
        try {
            if (config.shouldInstallSecurityManager()) {
                installSecurityManager();
            }
            Request cancellableRequest = requestFactory.createRequest(filteredRequest);
            return core.run(cancellableRequest);
        } finally {
            disableSecurityManager();
        }
    } finally {
        exitFileInactive(exitFile);
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Filter(org.junit.runner.manipulation.Filter) RegExTestCaseFilter(com.google.testing.junit.junit4.runner.RegExTestCaseFilter) SuiteTrimmingFilter(com.google.testing.junit.junit4.runner.SuiteTrimmingFilter) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) Request(org.junit.runner.Request) File(java.io.File) RunListener(org.junit.runner.notification.RunListener)

Example 5 with RunListener

use of org.junit.runner.notification.RunListener 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)

Aggregations

RunListener (org.junit.runner.notification.RunListener)51 Failure (org.junit.runner.notification.Failure)25 Description (org.junit.runner.Description)21 JUnitCore (org.junit.runner.JUnitCore)20 Result (org.junit.runner.Result)19 Test (org.junit.Test)18 RunNotifier (org.junit.runner.notification.RunNotifier)13 Request (org.junit.runner.Request)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 TextListener (org.junit.internal.TextListener)3 KieSession (org.kie.api.runtime.KieSession)3 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 HashMap (java.util.HashMap)2 ScenarioUtil.failureToFailure (org.drools.workbench.screens.testscenario.backend.server.ScenarioUtil.failureToFailure)2