Search in sources :

Example 11 with StepDurationTimeService

use of io.cucumber.core.runner.StepDurationTimeService in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_accumulate_time_from_steps_and_hooks.

@Test
void should_accumulate_time_from_steps_and_hooks() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    * first step\n" + "    * second step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition()), Arrays.asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), singletonList(new StubHookDefinition()))).build().run();
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"0\" errors=\"0\" tests=\"1\" time=\"0.004\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.004\">\n" + "        <system-out><![CDATA[" + "* first step................................................................passed\n" + "* second step...............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 12 with StepDurationTimeService

use of io.cucumber.core.runner.StepDurationTimeService 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)

Example 13 with StepDurationTimeService

use of io.cucumber.core.runner.StepDurationTimeService in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_add_step_hooks_to_step.

@Test
void should_add_step_hooks_to_step() {
    Feature feature = TestFeatureParser.parse("file:path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n" + "    When monkey arrives\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(emptyList(), singletonList(new StubHookDefinition("Hooks.beforestep_hooks_1()")), asList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"), new StubStepDefinition("monkey arrives", "StepDefs.monkey_arrives()")), asList(new StubHookDefinition("Hooks.afterstep_hooks_1()"), new StubHookDefinition("Hooks.afterstep_hooks_2()")), emptyList())).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"line\": 1,\n" + "    \"elements\": [\n" + "      {\n" + "        \"line\": 3,\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"description\": \"\",\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"type\": \"scenario\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"before\": [\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.beforestep_hooks_1()\"\n" + "                }\n" + "              }\n" + "            ],\n" + "            \"line\": 4,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"after\": [\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.afterstep_hooks_2()\"\n" + "                }\n" + "              },\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.afterstep_hooks_1()\"\n" + "                }\n" + "              }\n" + "            ],\n" + "            \"keyword\": \"Given \"\n" + "          },\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"before\": [\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.beforestep_hooks_1()\"\n" + "                }\n" + "              }\n" + "            ],\n" + "            \"line\": 5,\n" + "            \"name\": \"monkey arrives\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.monkey_arrives()\"\n" + "            },\n" + "            \"after\": [\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.afterstep_hooks_2()\"\n" + "                }\n" + "              },\n" + "              {\n" + "                \"result\": {\n" + "                  \"duration\": 1000000,\n" + "                  \"status\": \"passed\"\n" + "                },\n" + "                \"match\": {\n" + "                  \"location\": \"Hooks.afterstep_hooks_1()\"\n" + "                }\n" + "              }\n" + "            ],\n" + "            \"keyword\": \"When \"\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"name\": \"Banana party\",\n" + "    \"description\": \"\",\n" + "    \"id\": \"banana-party\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 14 with StepDurationTimeService

use of io.cucumber.core.runner.StepDurationTimeService in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_a_step_with_a_data_table.

@Test
void should_format_scenario_with_a_step_with_a_data_table() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n" + "      | aa | 11 |\n" + "      | bb | 22 |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()", DataTable.class))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"rows\": [\n" + "              {\n" + "                \"cells\": [\n" + "                  \"aa\",\n" + "                  \"11\"\n" + "                ]\n" + "              },\n" + "              {\n" + "                \"cells\": [\n" + "                  \"bb\",\n" + "                  \"22\"\n" + "                ]\n" + "              }\n" + "            ],\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 15 with StepDurationTimeService

use of io.cucumber.core.runner.StepDurationTimeService in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_handle_embed_with_name_from_a_hook.

@Test
void should_handle_embed_with_name_from_a_hook() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition("Hooks.before_hook_1()", testCaseState -> testCaseState.attach(new byte[] { 1, 2, 3 }, "mime-type;base64", "someEmbedding"))), singletonList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()")), emptyList())).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"before\": [\n" + "          {\n" + "            \"match\": {\n" + "              \"location\": \"Hooks.before_hook_1()\"\n" + "            },\n" + "            \"embeddings\": [\n" + "              {\n" + "                \"mime_type\": \"mime-type;base64\",\n" + "                \"data\": \"AQID\",\n" + "                \"name\": \"someEmbedding\"\n" + "              }\n" + "            ],\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ],\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Builder(io.cucumber.core.runtime.Runtime.Builder) ZoneId.of(java.time.ZoneId.of) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Scanner(java.util.Scanner) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) Clock.fixed(java.time.Clock.fixed) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Collections.emptyList(java.util.Collections.emptyList) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) EPOCH(java.time.Instant.EPOCH) Duration.ofMillis(java.time.Duration.ofMillis) InputStream(java.io.InputStream) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Aggregations

StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)20 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)20 Feature (io.cucumber.core.gherkin.Feature)19 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)19 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)19 UUID (java.util.UUID)19 Test (org.junit.jupiter.api.Test)19 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)18 DocString (io.cucumber.docstring.DocString)16 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)7 Arrays.asList (java.util.Arrays.asList)4 Collections.emptyList (java.util.Collections.emptyList)4 Collections.singletonList (java.util.Collections.singletonList)4 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)3 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)3 Runtime (io.cucumber.core.runtime.Runtime)3 Builder (io.cucumber.core.runtime.Runtime.Builder)3 DataTable (io.cucumber.datatable.DataTable)3 InputStream (java.io.InputStream)3