Search in sources :

Example 1 with TestCaseStarted

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

the class TestCase method emitTestCaseStarted.

private void emitTestCaseStarted(EventBus bus, Instant start, UUID executionId) {
    bus.send(new TestCaseStarted(start, this));
    Envelope envelope = new Envelope();
    envelope.setTestCaseStarted(new io.cucumber.messages.types.TestCaseStarted(0L, executionId.toString(), id.toString(), javaInstantToTimestamp(start)));
    bus.send(envelope);
}
Also used : Envelope(io.cucumber.messages.types.Envelope) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted)

Example 2 with TestCaseStarted

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

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step.

@Test
void test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result result = new Result(Status.SKIPPED, ZERO, null);
    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(), instanceOf(SkippedThrowable.class));
    assertThat(stepFailure.getException().getMessage(), is(equalTo("This step is skipped")));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), instanceOf(SkippedThrowable.class));
    assertThat(pickleFailure.getException().getMessage(), is(equalTo("This scenario is skipped")));
}
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) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 3 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted 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 4 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted 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 5 with TestCaseStarted

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

the class TestCaseResultObserverTest method undefined.

@Test
void undefined() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    bus.send(new SnippetsSuggestedEvent(Instant.now(), uri, testCase.getLocation(), testStep.getStep().getLocation(), new Suggestion(testStep.getStep().getText(), asList("mocked snippet 1", "mocked snippet 2", "mocked snippet 3"))));
    Result result = new Result(Status.UNDEFINED, Duration.ZERO, null);
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(UndefinedStepException.class));
    assertThat(exception.getCause().getMessage(), is("" + "The step 'mocked' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "mocked snippet 1\n" + "mocked snippet 2\n" + "mocked snippet 3\n"));
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)21 Test (org.junit.jupiter.api.Test)18 Result (io.cucumber.plugin.event.Result)16 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)16 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)16 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)15 Failure (org.junit.runner.notification.Failure)7 CucumberException (io.cucumber.core.exception.CucumberException)4 AssumptionViolatedException (org.junit.AssumptionViolatedException)4 TestAbortedException (org.opentest4j.TestAbortedException)4 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)3 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 Location (io.cucumber.plugin.event.Location)2 TestCase (io.cucumber.plugin.event.TestCase)2 EventBus (io.cucumber.core.eventbus.EventBus)1 ExceptionUtils.printStackTrace (io.cucumber.core.exception.ExceptionUtils.printStackTrace)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 Envelope (io.cucumber.messages.types.Envelope)1 EventListener (io.cucumber.plugin.EventListener)1