Search in sources :

Example 16 with RunNotifier

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

the class ErrorReportingRunnerTest method givenInvalidTestClassErrorAsCause.

@Test
public void givenInvalidTestClassErrorAsCause() {
    final List<Failure> firedFailures = new ArrayList<Failure>();
    InvalidTestClassError testClassError = new InvalidTestClassError(TestClassWithErrors.class, Arrays.asList(new Throwable("validation error 1"), new Throwable("validation error 2")));
    ErrorReportingRunner sut = new ErrorReportingRunner(TestClassWithErrors.class, testClassError);
    sut.run(new RunNotifier() {

        @Override
        public void fireTestFailure(Failure failure) {
            super.fireTestFailure(failure);
            firedFailures.add(failure);
        }
    });
    assertThat(firedFailures.size(), is(1));
    Throwable exception = firedFailures.get(0).getException();
    assertThat(exception, instanceOf(InvalidTestClassError.class));
    assertThat(((InvalidTestClassError) exception), is(testClassError));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) ArrayList(java.util.ArrayList) Failure(org.junit.runner.notification.Failure) InvalidTestClassError(org.junit.runners.model.InvalidTestClassError) Test(org.junit.Test)

Example 17 with RunNotifier

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

the class CancellableRequestFactory method cancelRun.

/**
   * Cancels the request created by this request factory.
   */
public void cancelRun() {
    cancelRequested = true;
    RunNotifier notifier = currentNotifier;
    if (notifier != null) {
        notifier.pleaseStop();
    }
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier)

Example 18 with RunNotifier

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

the class JUnitReporterTest method match_allow_stared_ignored.

@Test
public void match_allow_stared_ignored() {
    createAllowStartedIgnoredReporter();
    Step runnerStep = mockStep();
    Description runnerStepDescription = stepDescription(runnerStep);
    ExecutionUnitRunner executionUnitRunner = mockExecutionUnitRunner(runnerSteps(runnerStep));
    when(executionUnitRunner.describeChild(runnerStep)).thenReturn(runnerStepDescription);
    runNotifier = mock(RunNotifier.class);
    jUnitReporter.startExecutionUnit(executionUnitRunner, runNotifier);
    jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
    jUnitReporter.step(runnerStep);
    jUnitReporter.match(mock(Match.class));
    verify(runNotifier).fireTestStarted(executionUnitRunner.getDescription());
    verify(runNotifier).fireTestStarted(runnerStepDescription);
}
Also used : Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) Step(gherkin.formatter.model.Step) Scenario(gherkin.formatter.model.Scenario) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Example 19 with RunNotifier

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

the class JUnitReporterTest method creates_step_notifier_with_step_from_execution_unit_runner.

@Test
public void creates_step_notifier_with_step_from_execution_unit_runner() throws Exception {
    Step runnerStep = mockStep("Step Name");
    Description runnerStepDescription = stepDescription(runnerStep);
    ExecutionUnitRunner executionUnitRunner = mockExecutionUnitRunner(runnerSteps(runnerStep));
    when(executionUnitRunner.describeChild(runnerStep)).thenReturn(runnerStepDescription);
    RunNotifier notifier = mock(RunNotifier.class);
    jUnitReporter = new JUnitReporter(mock(Reporter.class), mock(Formatter.class), false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.startExecutionUnit(executionUnitRunner, notifier);
    jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
    jUnitReporter.step(mockStep("Step Name"));
    jUnitReporter.match(mock(Match.class));
    jUnitReporter.result(mockResult());
    verify(notifier).fireTestFinished(runnerStepDescription);
}
Also used : Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) Step(gherkin.formatter.model.Step) Scenario(gherkin.formatter.model.Scenario) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Example 20 with RunNotifier

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

Aggregations

RunNotifier (org.junit.runner.notification.RunNotifier)53 Failure (org.junit.runner.notification.Failure)16 Description (org.junit.runner.Description)15 Test (org.junit.Test)14 RunListener (org.junit.runner.notification.RunListener)13 Test (org.junit.jupiter.api.Test)9 Runner (org.junit.runner.Runner)9 InOrder (org.mockito.InOrder)7 Feature (io.cucumber.core.gherkin.Feature)5 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Request (org.junit.runner.Request)5 Result (org.junit.runner.Result)5 ParentRunner (org.junit.runners.ParentRunner)4 HashMap (java.util.HashMap)3 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)3 KieSession (org.kie.api.runtime.KieSession)3 Match (gherkin.formatter.model.Match)2 Scenario (gherkin.formatter.model.Scenario)2