Search in sources :

Example 26 with StubBackendSupplier

use of io.cucumber.core.runtime.StubBackendSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_a_failed_step.

@Test
void should_format_scenario_with_a_failed_step() {
    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(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()", new StubException()))).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" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"failed\",\n" + "              \"error_message\": \"the stack trace\",\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 27 with StubBackendSupplier

use of io.cucumber.core.runtime.StubBackendSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_outline_with_one_example.

@Test
void should_format_scenario_outline_with_one_example() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Fruit party\n" + "\n" + "  Scenario Outline: Monkey eats fruits\n" + "    Given there are <fruits>\n" + "      Examples: Fruit table\n" + "      | fruits  |\n" + "      | 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" + "    \"id\": \"fruit-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Fruit party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"fruit-party;monkey-eats-fruits;fruit-table;2\",\n" + "        \"keyword\": \"Scenario Outline\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats fruits\",\n" + "        \"line\": 7,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\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) 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 28 with StubBackendSupplier

use of io.cucumber.core.runtime.StubBackendSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_scenario_with_a_step_with_a_doc_string.

@Test
void should_format_scenario_with_a_step_with_a_doc_string() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n" + "    \"\"\"\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()", String.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" + "              \"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 29 with StubBackendSupplier

use of io.cucumber.core.runtime.StubBackendSupplier in project cucumber-jvm by cucumber.

the class JsonFormatterTest method should_format_feature_with_background.

@Test
void should_format_feature_with_background() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Background: There are bananas\n" + "    Given there are bananas\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Then the monkey eats bananas\n" + "\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("there are bananas", "StepDefs.there_are_bananas()"), new StubStepDefinition("the monkey eats bananas", "StepDefs.monkey_eats_bananas()"), new StubStepDefinition("the monkey eats more bananas", "StepDefs.monkey_eats_more_bananas()"))).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" + "        \"keyword\": \"Background\",\n" + "        \"name\": \"There are bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"background\",\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" + "        \"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\": 6,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Then \",\n" + "            \"name\": \"the monkey eats bananas\",\n" + "            \"line\": 7,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.monkey_eats_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      },\n" + "      {\n" + "        \"keyword\": \"Background\",\n" + "        \"name\": \"There are bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"background\",\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" + "        \"id\": \"banana-party;monkey-eats-more-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.002Z\",\n" + "        \"name\": \"Monkey eats more bananas\",\n" + "        \"line\": 9,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Then \",\n" + "            \"name\": \"the monkey eats more bananas\",\n" + "            \"line\": 10,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.monkey_eats_more_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 30 with StubBackendSupplier

use of io.cucumber.core.runtime.StubBackendSupplier in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_format_passed_scenario.

@Test
void should_format_passed_scenario() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).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\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + "        <system-out><![CDATA[" + "Given first step............................................................passed\n" + "When second step............................................................passed\n" + "Then third 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) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)79 Feature (io.cucumber.core.gherkin.Feature)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)78 Test (org.junit.jupiter.api.Test)78 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)71 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)56 UUID (java.util.UUID)54 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)19 DocString (io.cucumber.docstring.DocString)17 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)16 PrintStream (java.io.PrintStream)11 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)6 Runtime (io.cucumber.core.runtime.Runtime)6 DataTable (io.cucumber.datatable.DataTable)6 Arrays.asList (java.util.Arrays.asList)6 Collections.emptyList (java.util.Collections.emptyList)6 Collections.singletonList (java.util.Collections.singletonList)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6