Search in sources :

Example 31 with RunListener

use of org.junit.runner.notification.RunListener in project lucene-solr by apache.

the class TestMaxFailuresRule method testZombieThreadFailures.

@Test
public void testZombieThreadFailures() throws Exception {
    LuceneTestCase.replaceMaxFailureRule(new TestRuleIgnoreAfterMaxFailures(1));
    JUnitCore core = new JUnitCore();
    final StringBuilder results = new StringBuilder();
    core.addListener(new RunListener() {

        char lastTest;

        @Override
        public void testStarted(Description description) throws Exception {
            // success.
            lastTest = 'S';
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            // assumption failure.
            lastTest = 'A';
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            // failure
            lastTest = 'F';
            System.out.println(failure.getMessage());
        }

        @Override
        public void testFinished(Description description) throws Exception {
            results.append(lastTest);
        }
    });
    Result result = core.run(Nested2.class);
    if (Nested2.die != null) {
        Nested2.die.countDown();
        Nested2.zombie.join();
    }
    super.prevSysOut.println(results.toString());
    Assert.assertEquals(Nested2.TOTAL_ITERS, result.getRunCount());
    Assert.assertEquals(results.toString(), "SFAAAAAAAA", results.toString());
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 32 with RunListener

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

the class ScenarioRunner4JUnitTest method testNoKieWithGivenIDSession.

@Test
public void testNoKieWithGivenIDSession() throws Exception {
    HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
    ksessions.put("someID", ksession);
    Scenario scenario = new Scenario();
    scenario.getKSessions().add("someOtherID");
    ScenarioRunner4JUnit runner4JUnit = new ScenarioRunner4JUnit(scenario, ksessions);
    RunNotifier notifier = new RunNotifier();
    RunListener runListener = spy(new RunListener());
    notifier.addListener(runListener);
    runner4JUnit.run(notifier);
    verify(runListener).testFailure(any(Failure.class));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Failure(org.junit.runner.notification.Failure) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 33 with RunListener

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

the class ScenarioRunnerService method run.

private void run(final String identifier, final ScenarioRunner4JUnit scenarioRunner, final Event<TestResultMessage> testResultMessageEvent) {
    final List<org.guvnor.common.services.shared.test.Failure> failures = new ArrayList<org.guvnor.common.services.shared.test.Failure>();
    JUnitCore jUnitCore = new JUnitCore();
    jUnitCore.addListener(new RunListener() {

        @Override
        public void testAssumptionFailure(Failure failure) {
            failures.add(failureToFailure(failure));
        }
    });
    Result result = jUnitCore.run(scenarioRunner);
    failures.addAll(failuresToFailures(result.getFailures()));
    testResultMessageEvent.fire(new TestResultMessage(identifier, result.getRunCount(), result.getRunTime(), failures));
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) ArrayList(java.util.ArrayList) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) ScenarioUtil.failureToFailure(org.drools.workbench.screens.testscenario.backend.server.ScenarioUtil.failureToFailure) Failure(org.junit.runner.notification.Failure)

Example 34 with RunListener

use of org.junit.runner.notification.RunListener in project spf4j by zolyfarkas.

the class RunListenerRegisterTest method testRunListenerRegister.

@Test
// this is how RunListenerRegister works..
@SuppressFBWarnings("SEC_SIDE_EFFECT_CONSTRUCTOR")
public void testRunListenerRegister() {
    new RunListenerRegister();
    RunListener runListener = new RunListener();
    RunListenerRegister.addRunListener(runListener, true);
    Assert.assertTrue(RunListenerRegister.removeRunListener(runListener));
    Assert.assertFalse(RunListenerRegister.removeRunListener(runListener));
    try {
        new RunListenerRegister();
        Assert.fail();
    } catch (ExceptionInInitializerError ex) {
    // expected
    }
}
Also used : RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 35 with RunListener

use of org.junit.runner.notification.RunListener in project calcite-avatica by apache.

the class TestRunner method initializeJUnit.

/**
 * Sets up JUnit to run the tests for us.
 */
void initializeJUnit() {
    junitCore = new JUnitCore();
    junitCore.addListener(new RunListener() {

        @Override
        public void testStarted(Description description) throws Exception {
            LOG.debug("Starting {}", description);
        }

        @Override
        public void testFinished(Description description) throws Exception {
            LOG.debug("{}Finished {}{}", ANSI_GREEN, description, ANSI_RESET);
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            LOG.info("{}Failed {}{}", ANSI_RED, failure.getDescription(), ANSI_RESET, failure.getException());
        }
    });
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) SQLException(java.sql.SQLException) Failure(org.junit.runner.notification.Failure) 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