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);
}
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)))));
}
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);
}
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")));
}
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)));
}
Aggregations