Search in sources :

Example 21 with RunListener

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

the class ListenerTest method notifyListenersInTheOrderInWhichTheyAreAdded.

@Test
public void notifyListenersInTheOrderInWhichTheyAreAdded() {
    JUnitCore core = new JUnitCore();
    log = "";
    core.addListener(new RunListener() {

        @Override
        public void testRunStarted(Description description) throws Exception {
            log += "first ";
        }
    });
    core.addListener(new RunListener() {

        @Override
        public void testRunStarted(Description description) throws Exception {
            log += "second ";
        }
    });
    core.run(OneTest.class);
    assertEquals("first second ", log);
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 22 with RunListener

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

the class BlockJUnit4ClassRunnerTest method methodBlockAfterFireTestStarted.

@Test
public void methodBlockAfterFireTestStarted() {
    log = "";
    JUnitCore junit = new JUnitCore();
    junit.addListener(new RunListener() {

        @Override
        public void testStarted(Description description) throws Exception {
            log += " testStarted(" + description.getMethodName() + ")";
        }

        @Override
        public void testFinished(Description description) throws Exception {
            log += " testFinished(" + description.getMethodName() + ")";
        }
    });
    junit.run(MethodBlockAfterFireTestStarted.class);
    assertEquals(" testStarted(test) init test testFinished(test)", log);
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 23 with RunListener

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

the class JUnitCore method runMain.

/**
 * @param system system to run with
 * @param args from main()
 */
Result runMain(JUnitSystem system, String... args) {
    system.out().println("JUnit version " + Version.id());
    JUnitCommandLineParseResult jUnitCommandLineParseResult = JUnitCommandLineParseResult.parse(args);
    RunListener listener = new TextListener(system);
    addListener(listener);
    return run(jUnitCommandLineParseResult.createRequest(defaultComputer()));
}
Also used : TextListener(org.junit.internal.TextListener) RunListener(org.junit.runner.notification.RunListener)

Example 24 with RunListener

use of org.junit.runner.notification.RunListener in project drools-wb by kiegroup.

the class JunitRunnerHelper method runWithJunit.

public static Result runWithJunit(Path path, Runner runner, List<Failure> failures, List<Failure> failureDetails) {
    JUnitCore jUnitCore = new JUnitCore();
    jUnitCore.addListener(new RunListener() {

        @Override
        public void testAssumptionFailure(org.junit.runner.notification.Failure failure) {
            failureDetails.add(failureToFailure(path, failure));
        }
    });
    Result result = jUnitCore.run(runner);
    failures.addAll(failuresToFailures(path, result.getFailures()));
    return result;
}
Also used : JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result)

Example 25 with RunListener

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

the class JUnit4RunnerTest method getExpectedOutput.

private ByteArrayOutputStream getExpectedOutput(Class<?> testClass) {
    JUnitCore core = new JUnitCore();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(byteStream);
    printStream.println("JUnit4 Test Runner");
    RunListener listener = new TextListener(printStream);
    core.addListener(listener);
    Request request = Request.classWithoutSuiteMethod(testClass);
    core.run(request);
    printStream.close();
    return byteStream;
}
Also used : PrintStream(java.io.PrintStream) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) TextListener(org.junit.internal.TextListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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