Search in sources :

Example 16 with Result

use of io.cucumber.plugin.event.Result in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_test_failure_and_test_finished_for_failed_hook.

@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_hook() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result stepResult = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), stepResult));
    bus.send(new TestStepStarted(now(), testCase, mock(HookTestStep.class)));
    Throwable exception = new Exception("Oops");
    Result result = new Result(Status.FAILED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mock(HookTestStep.class), result));
    // Hooks are not included in step failure
    verify(runNotifier, never()).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) MultipleFailureException(org.junit.runners.model.MultipleFailureException) AssumptionViolatedException(org.junit.AssumptionViolatedException) CucumberException(io.cucumber.core.exception.CucumberException) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 17 with Result

use of io.cucumber.plugin.event.Result in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step_with_assumption_violated.

@Test
void test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step_with_assumption_violated() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Throwable exception = new AssumptionViolatedException("Oops");
    Result result = new Result(Status.SKIPPED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier).fireTestAssumptionFailed(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure stepFailure = failureArgumentCaptor.getValue();
    assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.getException(), is(equalTo(exception)));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) AssumptionViolatedException(org.junit.AssumptionViolatedException) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 18 with Result

use of io.cucumber.plugin.event.Result in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method should_be_skipped_for_skipped_result.

@Test
public void should_be_skipped_for_skipped_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    Result stepResult = new Result(SKIPPED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(SKIPPED, ZERO, null);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(SkipException.class));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SkipException(org.testng.SkipException) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 19 with Result

use of io.cucumber.plugin.event.Result in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method should_be_skipped_for_pending_result.

@Test
public void should_be_skipped_for_pending_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    Exception error = new TestPendingException();
    Result stepResult = new Result(PENDING, ZERO, error);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(PENDING, ZERO, error);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertThat(exception.getCause(), is(error));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 20 with Result

use of io.cucumber.plugin.event.Result in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method should_not_be_passed_for_failed_result.

@Test
public void should_not_be_passed_for_failed_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    Result stepResult = new Result(FAILED, ZERO, error);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(FAILED, ZERO, error);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertEquals(exception.getCause(), error);
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Aggregations

Result (io.cucumber.plugin.event.Result)56 Test (org.junit.jupiter.api.Test)41 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)29 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)26 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)15 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)14 Test (org.testng.annotations.Test)9 UUID (java.util.UUID)7 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Status (io.cucumber.plugin.event.Status)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 TestAbortedException (org.opentest4j.TestAbortedException)6 EventBus (io.cucumber.core.eventbus.EventBus)5 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)5 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)5 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)5 OutputStream (java.io.OutputStream)5