Search in sources :

Example 11 with StubFeatureSupplier

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

the class PrettyFormatterTest method should_align_the_indentation_of_location_strings.

@Test
void should_align_the_indentation_of_location_strings() {
    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 PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:3"), new StubStepDefinition("second step", "path/step_definitions.java:7"), new StubStepDefinition("third step", "path/step_definitions.java:11"))).build().run();
    assertThat(out, isBytesEqualTo("" + "\n" + "Scenario: scenario name # path/test.feature:2\n" + "  Given first step      # path/step_definitions.java:3\n" + "  When second step      # path/step_definitions.java:7\n" + "  Then third step       # path/step_definitions.java:11\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 12 with StubFeatureSupplier

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

the class PrettyFormatterTest method should_print_table.

@Test
void should_print_table() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Test feature\n" + "  Scenario: Test Scenario\n" + "    Given first step\n" + "      | key1     | key2     |\n" + "      | value1   | value2   |\n" + "      | another1 | another2 |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class))).build().run();
    assertThat(out, isBytesEqualTo("" + "\n" + "Scenario: Test Scenario # path/test.feature:2\n" + "  Given first step      # path/step_definitions.java:7\n" + "    | key1     | key2     |\n" + "    | value1   | value2   |\n" + "    | another1 | another2 |\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 13 with StubFeatureSupplier

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

the class PrettyFormatterTest method should_handle_scenario_outline.

@Test
void should_handle_scenario_outline() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario Outline: <name>\n" + "    Given first step\n" + "    Then <arg> step\n" + "    Examples: examples name\n" + "      |  name  |  arg   |\n" + "      | name 1 | second |\n" + "      | name 2 | third  |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:3"), new StubStepDefinition("second step", "path/step_definitions.java:7"), new StubStepDefinition("third step", "path/step_definitions.java:11"))).build().run();
    assertThat(out, bytesContainsString("" + "\n" + "Scenario Outline: name 1 # path/test.feature:7\n" + "  Given first step       # path/step_definitions.java:3\n" + "  Then second step       # path/step_definitions.java:7\n" + "\n" + "Scenario Outline: name 2 # path/test.feature:8\n" + "  Given first step       # path/step_definitions.java:3\n" + "  Then third step        # path/step_definitions.java:11\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 14 with StubFeatureSupplier

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

the class PrettyFormatterTest method should_print_error_message_for_failed_steps.

@Test
void should_print_error_message_for_failed_steps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:3", new StubException()))).build().run();
    assertThat(out, bytesContainsString("" + "  Given first step      # path/step_definitions.java:3\n" + "      the stack trace\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 15 with StubFeatureSupplier

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

the class PrettyFormatterTest method should_print_output_from_afterStep_hooks.

@Test
void should_print_output_from_afterStep_hooks() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(emptyList(), emptyList(), asList(new StubStepDefinition("first step", "path/step_definitions.java:3"), new StubStepDefinition("second step", "path/step_definitions.java:4")), singletonList(new StubHookDefinition(testCaseState -> testCaseState.log("printed from afterstep hook"))), emptyList())).build().run();
    assertThat(out, bytesContainsString("" + "  Given first step      # path/step_definitions.java:3\n" + "\n" + "    printed from afterstep hook\n" + "\n" + "  When second step      # path/step_definitions.java:4\n" + "\n" + "    printed from afterstep hook" + "\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) Formats.ansi(io.cucumber.core.plugin.Formats.ansi) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Collections.singletonList(java.util.Collections.singletonList) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStaticHookDefinition(io.cucumber.core.backend.StubStaticHookDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) BytesContainsString.bytesContainsString(io.cucumber.core.plugin.BytesContainsString.bytesContainsString) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) BytesEqualTo.isBytesEqualTo(io.cucumber.core.plugin.BytesEqualTo.isBytesEqualTo) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) EventBus(io.cucumber.core.eventbus.EventBus) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) Collections.emptyList(java.util.Collections.emptyList) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) TestDefinitionArgument.createArguments(io.cucumber.core.runner.TestDefinitionArgument.createArguments) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)78 Feature (io.cucumber.core.gherkin.Feature)77 ByteArrayOutputStream (java.io.ByteArrayOutputStream)77 Test (org.junit.jupiter.api.Test)77 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)70 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)55 UUID (java.util.UUID)53 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)25 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)18 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