Search in sources :

Example 1 with StepDefinedEvent

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

the class UnusedStepsSummaryPrinterTest method verifyUnusedStepsPrinted.

@Test
void verifyUnusedStepsPrinted() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    UnusedStepsSummaryPrinter summaryPrinter = new UnusedStepsSummaryPrinter(out);
    summaryPrinter.setMonochrome(true);
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    summaryPrinter.setEventPublisher(bus);
    // Register two steps, use one, then finish the test run
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
    bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/belly.feature:3"), new Result(Status.UNUSED, Duration.ZERO, null)));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
    bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/gut.feature:7"), new Result(Status.UNUSED, Duration.ZERO, null)));
    bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
    // Verify produced output
    assertThat(out, isBytesEqualTo("1 Unused steps:\n" + "my/tummy.feature:5 # some more cukes\n"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 2 with StepDefinedEvent

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

the class CachingGlue method emitStepDefined.

private void emitStepDefined(CoreStepDefinition coreStepDefinition) {
    bus.send(new StepDefinedEvent(bus.getInstant(), new io.cucumber.plugin.event.StepDefinition(coreStepDefinition.getStepDefinition().getLocation(), coreStepDefinition.getExpression().getSource())));
    io.cucumber.messages.types.StepDefinition messagesStepDefinition = new io.cucumber.messages.types.StepDefinition();
    messagesStepDefinition.setId(coreStepDefinition.getId().toString());
    messagesStepDefinition.setPattern(new StepDefinitionPattern(coreStepDefinition.getExpression().getSource(), getExpressionType(coreStepDefinition)));
    coreStepDefinition.getDefinitionLocation().ifPresent(reference -> messagesStepDefinition.setSourceReference(createSourceReference(reference)));
    Envelope envelope = new Envelope();
    envelope.setStepDefinition(messagesStepDefinition);
    bus.send(envelope);
}
Also used : StepDefinitionPattern(io.cucumber.messages.types.StepDefinitionPattern) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) StepDefinition(io.cucumber.core.backend.StepDefinition) Envelope(io.cucumber.messages.types.Envelope)

Example 3 with StepDefinedEvent

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

the class RuntimeTest method generates_events_for_glue_and_scenario_scoped_glue.

@Test
void generates_events_for_glue_and_scenario_scoped_glue() {
    final Feature feature = TestFeatureParser.parse("test.feature", "" + "Feature: feature name\n" + "  Scenario: Run a scenario once\n" + "    Given global scoped\n" + "    And scenario scoped\n" + "  Scenario: Then do it again\n" + "    Given global scoped\n" + "    And scenario scoped\n" + "");
    final List<StepDefinition> stepDefinedEvents = new ArrayList<>();
    Plugin eventListener = (EventListener) publisher -> publisher.registerHandlerFor(StepDefinedEvent.class, (StepDefinedEvent event) -> {
        stepDefinedEvents.add(event.getStepDefinition());
    });
    final MockedStepDefinition mockedStepDefinition = new MockedStepDefinition();
    final MockedScenarioScopedStepDefinition mockedScenarioScopedStepDefinition = new MockedScenarioScopedStepDefinition();
    BackendSupplier backendSupplier = new TestBackendSupplier() {

        private Glue glue;

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            this.glue = glue;
            glue.addStepDefinition(mockedStepDefinition);
        }

        @Override
        public void buildWorld() {
            glue.addStepDefinition(mockedScenarioScopedStepDefinition);
        }
    };
    FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
    Runtime.builder().withBackendSupplier(backendSupplier).withAdditionalPlugins(eventListener).withEventBus(new TimeServiceEventBus(new StepDurationTimeService(ZERO), UUID::randomUUID)).withFeatureSupplier(featureSupplier).build().run();
    assertThat(stepDefinedEvents.get(0).getPattern(), is(mockedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.get(1).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
    // Twice, once for each scenario
    assertThat(stepDefinedEvents.get(2).getPattern(), is(mockedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.get(3).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.size(), is(4));
}
Also used : TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) ArrayList(java.util.ArrayList) Feature(io.cucumber.core.gherkin.Feature) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) Glue(io.cucumber.core.backend.Glue) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.plugin.event.StepDefinition) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) UUID(java.util.UUID) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Plugin(io.cucumber.plugin.Plugin) Test(org.junit.jupiter.api.Test)

Aggregations

StepDefinedEvent (io.cucumber.plugin.event.StepDefinedEvent)3 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 Glue (io.cucumber.core.backend.Glue)1 StepDefinition (io.cucumber.core.backend.StepDefinition)1 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)1 Feature (io.cucumber.core.gherkin.Feature)1 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)1 TestBackendSupplier (io.cucumber.core.runner.TestBackendSupplier)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 Envelope (io.cucumber.messages.types.Envelope)1 StepDefinitionPattern (io.cucumber.messages.types.StepDefinitionPattern)1 ConcurrentEventListener (io.cucumber.plugin.ConcurrentEventListener)1 EventListener (io.cucumber.plugin.EventListener)1 Plugin (io.cucumber.plugin.Plugin)1 Result (io.cucumber.plugin.event.Result)1 StepDefinition (io.cucumber.plugin.event.StepDefinition)1 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1