Search in sources :

Example 1 with StepDurationTimeService

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

the class TestNGFormatterTest method testDurationCalculationOfStepsAndHooks.

@Test
void testDurationCalculationOfStepsAndHooks() {
    Feature feature1 = TestFeatureParser.parse("path/feature1.feature", "" + "Feature: feature_1\n" + "  Scenario: scenario_1\n" + "    When step\n" + "    Then step\n" + "  Scenario: scenario_2\n" + "    When step\n" + "    Then step\n");
    Feature feature2 = TestFeatureParser.parse("path/feature2.feature", "" + "Feature: feature_2\n" + "  Scenario: scenario_3\n" + "    When step\n" + "    Then step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(() -> Arrays.asList(feature1, feature2)).withAdditionalPlugins(timeService, new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition()), singletonList(new StubStepDefinition("step")), singletonList(new StubHookDefinition()))).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"3\" passed=\"3\" failed=\"0\" skipped=\"0\">" + "    <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + "        <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + "            <class name=\"feature_1\">" + "                <test-method name=\"scenario_1\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00.004Z\"/>" + "                <test-method name=\"scenario_2\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.004Z\" finished-at=\"1970-01-01T00:00:00.008Z\"/>" + "            </class>" + "            <class name=\"feature_2\">" + "                <test-method name=\"scenario_3\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.008Z\" finished-at=\"1970-01-01T00:00:00.012Z\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) 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 2 with StepDurationTimeService

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

the class JsonFormatterTest method should_format_scenario_with_a_rule.

@Test
void should_format_scenario_with_a_rule() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Rule: This is all monkey business\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(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"line\": 1,\n" + "    \"elements\": [\n" + "      {\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"line\": 4,\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"description\": \"\",\n" + "        \"id\": \";monkey-eats-bananas\",\n" + "        \"type\": \"scenario\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"line\": 5,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Given \"\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) 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 3 with StepDurationTimeService

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

the class JsonFormatterTest method should_handle_write_from_a_hook.

@Test
void should_handle_write_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.log("printed from hook"))), 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" + "            \"output\": [\n" + "              \"printed from hook\"\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)

Example 4 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_doc_string_and_content_type.

@Test
void should_format_scenario_with_a_step_with_a_doc_string_and_content_type() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n" + "    \"\"\"text/plain\n" + "    doc string content\n" + "    \"\"\"\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()", DocString.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" + "            \"doc_string\": {\n" + "              \"content_type\": \"text/plain\",\n" + "              \"value\": \"doc string content\",\n" + "              \"line\": 5\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 5 with StepDurationTimeService

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

the class JsonFormatterTest method should_format_feature_and_scenario_with_tags.

@Test
void should_format_feature_and_scenario_with_tags() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "@Party @Banana\n" + "Feature: Banana party\n" + "  @Monkey\n" + "  Scenario: Monkey eats more bananas\n" + "    Then the monkey eats more 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(new StubStepDefinition("the monkey eats more bananas", "StepDefs.monkey_eats_more_bananas()"))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"line\": 2,\n" + "    \"elements\": [\n" + "      {\n" + "        \"line\": 4,\n" + "        \"name\": \"Monkey eats more bananas\",\n" + "        \"description\": \"\",\n" + "        \"id\": \"banana-party;monkey-eats-more-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" + "            \"line\": 5,\n" + "            \"name\": \"the monkey eats more bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.monkey_eats_more_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Then \"\n" + "          }\n" + "        ],\n" + "        \"tags\": [\n" + "          {\n" + "            \"name\": \"@Party\"\n" + "          },\n" + "          {\n" + "            \"name\": \"@Banana\"\n" + "          },\n" + "          {\n" + "            \"name\": \"@Monkey\"\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" + "        \"name\": \"@Party\",\n" + "        \"type\": \"Tag\",\n" + "        \"location\": {\n" + "          \"line\": 1,\n" + "          \"column\": 1\n" + "        }\n" + "      },\n" + "      {\n" + "        \"name\": \"@Banana\",\n" + "        \"type\": \"Tag\",\n" + "        \"location\": {\n" + "          \"line\": 1,\n" + "          \"column\": 8\n" + "        }\n" + "      }\n" + "    ]\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)

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