Search in sources :

Example 41 with RunListener

use of org.junit.runner.notification.RunListener in project cucumber-jvm by cucumber.

the class CucumberTest method cucumber_distinguishes_between_identical_features.

@Test
void cucumber_distinguishes_between_identical_features() throws Exception {
    RunNotifier notifier = new RunNotifier();
    RunListener listener = Mockito.mock(RunListener.class);
    notifier.addListener(listener);
    Request.classes(ValidEmpty.class).getRunner().run(notifier);
    {
        InOrder order = Mockito.inOrder(listener);
        order.verify(listener).testStarted(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
        order.verify(listener).testFinished(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
        order.verify(listener).testStarted(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
        order.verify(listener).testFinished(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
    }
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) InOrder(org.mockito.InOrder) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.jupiter.api.Test)

Example 42 with RunListener

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

the class SlaveMain method execute.

/**
 * Execute tests.
 */
private void execute(Iterator<String> classNames) throws Throwable {
    final RunNotifier fNotifier = new OrderedRunNotifier();
    final Result result = new Result();
    final Writer debug = debugMessagesFile == null ? new NullWriter() : new OutputStreamWriter(new FileOutputStream(debugMessagesFile), "UTF-8");
    fNotifier.addListener(result.createListener());
    fNotifier.addListener(new StreamFlusherDecorator(new NoExceptionRunListenerDecorator(new RunListenerEmitter(serializer)) {

        @Override
        protected void exception(Throwable t) {
            warn("Event serializer exception.", t);
        }
    }));
    fNotifier.addListener(new RunListener() {

        public void testRunFinished(Result result) throws Exception {
            debug(debug, "testRunFinished(T:" + result.getRunCount() + ";F:" + result.getFailureCount() + ";I:" + result.getIgnoreCount() + ")");
            serializer.flush();
        }

        @Override
        public void testRunStarted(Description description) throws Exception {
            debug(debug, "testRunStarted(" + description + ")");
            serializer.flush();
        }

        @Override
        public void testStarted(Description description) throws Exception {
            debug(debug, "testStarted(" + description + ")");
            serializer.flush();
        }

        public void testFinished(Description description) throws Exception {
            debug(debug, "testFinished(" + description + ")");
            serializer.flush();
        }

        @Override
        public void testIgnored(Description description) throws Exception {
            debug(debug, "testIgnored(T:" + description + ")");
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            debug(debug, "testFailure(T:" + failure + ")");
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            try {
                debug(debug, "testAssumptionFailure(T:" + failure + ")");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    /*
     * Instantiate method filter if any.
     */
    String methodFilterGlob = Strings.emptyToNull(System.getProperty(SysGlobals.SYSPROP_TESTMETHOD()));
    Filter methodFilter = Filter.ALL;
    if (methodFilterGlob != null) {
        methodFilter = new MethodGlobFilter(methodFilterGlob);
    }
    /*
     * Important. Run each class separately so that we get separate 
     * {@link RunListener} callbacks for the top extracted description.
     */
    debug(debug, "Entering main suite loop.");
    try {
        while (classNames.hasNext()) {
            final String clName = classNames.next();
            debug(debug, "Instantiating: " + clName);
            Class<?> clazz = instantiate(clName);
            if (clazz == null)
                continue;
            Request request = Request.aClass(clazz);
            try {
                Runner runner = request.getRunner();
                methodFilter.apply(runner);
                // New RunListener instances should be added per class and then removed from the RunNotifier
                ArrayList<RunListener> runListenerInstances = instantiateRunListeners();
                for (RunListener runListener : runListenerInstances) {
                    fNotifier.addListener(runListener);
                }
                fNotifier.fireTestRunStarted(runner.getDescription());
                debug(debug, "Runner.run(" + clName + ")");
                runner.run(fNotifier);
                debug(debug, "Runner.done(" + clName + ")");
                fNotifier.fireTestRunFinished(result);
                for (RunListener runListener : runListenerInstances) {
                    fNotifier.removeListener(runListener);
                }
            } catch (NoTestsRemainException e) {
            // Don't complain if all methods have been filtered out.
            // I don't understand the reason why this exception has been
            // built in to filters at all.
            }
        }
    } catch (Throwable t) {
        debug(debug, "Main suite loop error: " + t);
        throw t;
    } finally {
        debug(debug, "Leaving main suite loop.");
        debug.close();
    }
}
Also used : RandomizedRunner(com.carrotsearch.randomizedtesting.RandomizedRunner) Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) MethodGlobFilter(com.carrotsearch.randomizedtesting.MethodGlobFilter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) Result(org.junit.runner.Result) Failure(org.junit.runner.notification.Failure) RunNotifier(org.junit.runner.notification.RunNotifier) Request(org.junit.runner.Request) IOException(java.io.IOException) IOException(java.io.IOException) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) RunListener(org.junit.runner.notification.RunListener) MethodGlobFilter(com.carrotsearch.randomizedtesting.MethodGlobFilter) Filter(org.junit.runner.manipulation.Filter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 43 with RunListener

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

the class WithNestedTestClass method runTests.

public static FullResult runTests(final Class<?>... classes) {
    try {
        final FullResult fullResult = new FullResult();
        // Run on a separate thread so that it appears as we're not running in an IDE.
        Thread thread = new Thread() {

            @Override
            public void run() {
                final JUnitCore core = new JUnitCore();
                core.addListener(new PrintEventListener(sysout));
                core.addListener(new RunListener() {

                    @Override
                    public void testAssumptionFailure(Failure failure) {
                        fullResult.assumptionIgnored.incrementAndGet();
                    }
                });
                fullResult.result = core.run(classes);
            }
        };
        thread.start();
        thread.join();
        return fullResult;
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 44 with RunListener

use of org.junit.runner.notification.RunListener in project junit4 by junit-team.

the class JUnit4TestAdapterCache method getNotifier.

public RunNotifier getNotifier(final TestResult result, final JUnit4TestAdapter adapter) {
    RunNotifier notifier = new RunNotifier();
    notifier.addListener(new RunListener() {

        @Override
        public void testFailure(Failure failure) throws Exception {
            result.addError(asTest(failure.getDescription()), failure.getException());
        }

        @Override
        public void testFinished(Description description) throws Exception {
            result.endTest(asTest(description));
        }

        @Override
        public void testStarted(Description description) throws Exception {
            result.startTest(asTest(description));
        }
    });
    return notifier;
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 45 with RunListener

use of org.junit.runner.notification.RunListener in project junit4 by junit-team.

the class FailureList method result.

public Result result() {
    Result result = new Result();
    RunListener listener = result.createListener();
    for (Failure failure : failures) {
        try {
            listener.testFailure(failure);
        } catch (Exception e) {
            throw new RuntimeException("I can't believe this happened");
        }
    }
    return result;
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener)

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