Search in sources :

Example 1 with TestStepStarted

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

the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.

@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
    EventHandler handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    TestCase testCase = mock(TestCase.class);
    TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler, never()).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase) EventHandler(io.cucumber.plugin.event.EventHandler) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 2 with TestStepStarted

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

the class PickleStepTestStepTest method step_execution_time_is_measured.

@Test
void step_execution_time_is_measured() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestStep step = new PickleStepTestStep(UUID.randomUUID(), URI.create("file:path/to.feature"), feature.getPickles().get(0).getSteps().get(0), definitionMatch);
    when(bus.getInstant()).thenReturn(ofEpochMilli(234L), ofEpochMilli(1234L));
    step.run(testCase, bus, state, ExecutionMode.RUN);
    ArgumentCaptor<TestCaseEvent> captor = forClass(TestCaseEvent.class);
    verify(bus, times(4)).send(captor.capture());
    List<TestCaseEvent> allValues = captor.getAllValues();
    TestStepStarted started = (TestStepStarted) allValues.get(0);
    TestStepFinished finished = (TestStepFinished) allValues.get(2);
    assertAll(() -> assertThat(started.getInstant(), is(equalTo(ofEpochMilli(234L)))), () -> assertThat(finished.getInstant(), is(equalTo(ofEpochMilli(1234L)))), () -> assertThat(finished.getResult().getDuration(), is(equalTo(ofMillis(1000L)))));
}
Also used : TestCaseEvent(io.cucumber.plugin.event.TestCaseEvent) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) Feature(io.cucumber.core.gherkin.Feature) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 3 with TestStepStarted

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

the class TestStep method emitTestStepStarted.

private void emitTestStepStarted(TestCase testCase, EventBus bus, UUID textExecutionId, Instant startTime) {
    bus.send(new TestStepStarted(startTime, testCase, this));
    Envelope envelope = new Envelope();
    envelope.setTestStepStarted(new io.cucumber.messages.types.TestStepStarted(textExecutionId.toString(), id.toString(), javaInstantToTimestamp(startTime)));
    bus.send(envelope);
}
Also used : Envelope(io.cucumber.messages.types.Envelope) TestStepStarted(io.cucumber.plugin.event.TestStepStarted)

Example 4 with TestStepStarted

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

use of io.cucumber.plugin.event.TestStepStarted 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)

Aggregations

TestStepStarted (io.cucumber.plugin.event.TestStepStarted)18 Test (org.junit.jupiter.api.Test)17 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)15 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)15 Result (io.cucumber.plugin.event.Result)14 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)14 Failure (org.junit.runner.notification.Failure)7 CucumberException (io.cucumber.core.exception.CucumberException)4 AssumptionViolatedException (org.junit.AssumptionViolatedException)4 TestAbortedException (org.opentest4j.TestAbortedException)4 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 EventBus (io.cucumber.core.eventbus.EventBus)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)2 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)2 UUID (java.util.UUID)2 Feature (io.cucumber.core.gherkin.Feature)1 Envelope (io.cucumber.messages.types.Envelope)1 EventHandler (io.cucumber.plugin.event.EventHandler)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1