Search in sources :

Example 1 with TestCaseEvent

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

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

the class PickleStepTestStepTest method result_is_result_from_step_when_step_hook_does_not_pass.

@Test
void result_is_result_from_step_when_step_hook_does_not_pass() throws Throwable {
    RuntimeException runtimeException = new RuntimeException();
    Result failure = new Result(Status.FAILED, ZERO, runtimeException);
    doThrow(runtimeException).when(definitionMatch).runStep(any(TestCaseState.class));
    ExecutionMode nextExecutionMode = step.run(testCase, bus, state, ExecutionMode.RUN);
    assertThat(nextExecutionMode, is(ExecutionMode.SKIP));
    assertThat(state.getStatus(), is(equalTo(FAILED)));
    ArgumentCaptor<TestCaseEvent> captor = forClass(TestCaseEvent.class);
    verify(bus, times(12)).send(captor.capture());
    List<TestCaseEvent> allValues = captor.getAllValues();
    assertThat(((TestStepFinished) allValues.get(6)).getResult(), is(equalTo(failure)));
}
Also used : TestCaseEvent(io.cucumber.plugin.event.TestCaseEvent) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 3 with TestCaseEvent

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

the class PickleStepTestStepTest method result_is_result_from_hook_when_before_step_hook_does_not_pass.

@Test
void result_is_result_from_hook_when_before_step_hook_does_not_pass() {
    Exception exception = new RuntimeException();
    doThrow(exception).when(beforeHookDefinition).execute(any(TestCaseState.class));
    Result failure = new Result(Status.FAILED, ZERO, exception);
    ExecutionMode nextExecutionMode = step.run(testCase, bus, state, ExecutionMode.RUN);
    assertThat(nextExecutionMode, is(ExecutionMode.SKIP));
    assertThat(state.getStatus(), is(equalTo(FAILED)));
    ArgumentCaptor<TestCaseEvent> captor = forClass(TestCaseEvent.class);
    verify(bus, times(12)).send(captor.capture());
    List<TestCaseEvent> allValues = captor.getAllValues();
    assertThat(((TestStepFinished) allValues.get(2)).getResult(), is(equalTo(failure)));
}
Also used : TestCaseEvent(io.cucumber.plugin.event.TestCaseEvent) StubPendingException(io.cucumber.core.backend.StubPendingException) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

TestCaseEvent (io.cucumber.plugin.event.TestCaseEvent)3 Test (org.junit.jupiter.api.Test)3 Result (io.cucumber.plugin.event.Result)2 StubPendingException (io.cucumber.core.backend.StubPendingException)1 Feature (io.cucumber.core.gherkin.Feature)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)1 TestAbortedException (org.opentest4j.TestAbortedException)1