Search in sources :

Example 1 with PickleStepTestStep

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

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

the class UsageFormatterTest method resultWithNullDuration.

// Note: Duplicate of above test
@Test
void resultWithNullDuration() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    PickleStepTestStep testStep = mockTestStep();
    Result result = new Result(Status.PASSED, Duration.ZERO, null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertThat(usageMap.size(), is(equalTo(1)));
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertThat(durationEntries.size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getName(), is(equalTo("step")));
    assertThat(durationEntries.get(0).getDurations().size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getDurations().get(0).getDuration(), is(equalTo(0.0)));
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 3 with PickleStepTestStep

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

the class UsageFormatterTest method mockTestStep.

private PickleStepTestStep mockTestStep() {
    PickleStepTestStep testStep = mock(PickleStepTestStep.class, Mockito.RETURNS_MOCKS);
    when(testStep.getPattern()).thenReturn("stepDef");
    when(testStep.getStepText()).thenReturn("step");
    return testStep;
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep)

Example 4 with PickleStepTestStep

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

the class JUnitReporter method handleTestStepFinished.

private void handleTestStepFinished(TestStepFinished event) {
    if (event.getTestStep() instanceof PickleStepTestStep) {
        PickleStepTestStep testStep = (PickleStepTestStep) event.getTestStep();
        handleStepResult(testStep, event.getResult());
    } else {
        handleHookResult(event.getResult());
    }
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep)

Example 5 with PickleStepTestStep

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

the class TeamCityPlugin method extractName.

private String extractName(TestStep step) {
    if (step instanceof PickleStepTestStep) {
        PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) step;
        return pickleStepTestStep.getStep().getText();
    }
    if (step instanceof HookTestStep) {
        HookTestStep hook = (HookTestStep) step;
        HookType hookType = hook.getHookType();
        switch(hookType) {
            case BEFORE:
                return "Before";
            case AFTER:
                return "After";
            case BEFORE_STEP:
                return "BeforeStep";
            case AFTER_STEP:
                return "AfterStep";
            default:
                return hookType.name().toLowerCase(Locale.US);
        }
    }
    return "Unknown step";
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) HookTestStep(io.cucumber.plugin.event.HookTestStep) HookType(io.cucumber.plugin.event.HookType)

Aggregations

PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)19 TestCase (io.cucumber.plugin.event.TestCase)4 HookTestStep (io.cucumber.plugin.event.HookTestStep)3 StepArgument (io.cucumber.plugin.event.StepArgument)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.jupiter.api.Test)3 EventBus (io.cucumber.core.eventbus.EventBus)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 DataTableArgument (io.cucumber.plugin.event.DataTableArgument)2 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)2 Result (io.cucumber.plugin.event.Result)2 TestStep (io.cucumber.plugin.event.TestStep)2 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CucumberException (io.cucumber.core.exception.CucumberException)1 DataTableArgument (io.cucumber.core.gherkin.DataTableArgument)1 DataTableFormatter (io.cucumber.datatable.DataTableFormatter)1 Step (io.cucumber.messages.types.Step)1