Search in sources :

Example 11 with RuntimeOptionsBuilder

use of io.cucumber.core.options.RuntimeOptionsBuilder 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)

Example 12 with RuntimeOptionsBuilder

use of io.cucumber.core.options.RuntimeOptionsBuilder in project cucumber-jvm by cucumber.

the class PrettyFormatterTest method should_print_error_message_for_after_hooks.

@Test
void should_print_error_message_for_after_hooks() {
    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(emptyList(), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), singletonList(new StubHookDefinition(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) 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)

Example 13 with RuntimeOptionsBuilder

use of io.cucumber.core.options.RuntimeOptionsBuilder in project cucumber-jvm by cucumber.

the class DryRunTest method dry_run_passes_pending_step.

@Test
void dry_run_passes_pending_step() {
    Feature pending = TestFeatureParser.parse("2/pending.feature", "Feature: pending\n" + "  Scenario: pending\n" + "    * pending step\n");
    StepStatusSpy out = new StepStatusSpy();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(pending)).withAdditionalPlugins(out).withBackendSupplier(backend).withRuntimeOptions(new RuntimeOptionsBuilder().setDryRun().build()).build().run();
    assertThat(out.toString(), is("" + "pending\n" + "    PASSED\n"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 14 with RuntimeOptionsBuilder

use of io.cucumber.core.options.RuntimeOptionsBuilder in project cucumber-jvm by cucumber.

the class DryRunTest method dry_run_skips_all_steps_after_undefined_step.

@Test
void dry_run_skips_all_steps_after_undefined_step() {
    StepStatusSpy out = new StepStatusSpy();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(undefined)).withAdditionalPlugins(out).withBackendSupplier(backend).withRuntimeOptions(new RuntimeOptionsBuilder().setDryRun().build()).build().run();
    assertThat(out.toString(), is("" + "undefined\n" + "    UNDEFINED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Test(org.junit.jupiter.api.Test)

Example 15 with RuntimeOptionsBuilder

use of io.cucumber.core.options.RuntimeOptionsBuilder in project cucumber-jvm by cucumber.

the class JsonFormatterTest method featureWithOutlineTestParallel.

@Test
void featureWithOutlineTestParallel() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    createRuntime(out).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run();
    InputStream resourceAsStream = getClass().getResourceAsStream("JsonPrettyFormatterTest.json");
    String expected = new Scanner(resourceAsStream, "UTF-8").useDelimiter("\\A").next();
    assertJsonEquals(expected, out);
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)28 Test (org.junit.jupiter.api.Test)27 Feature (io.cucumber.core.gherkin.Feature)20 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)13 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)13 Collections.emptyList (java.util.Collections.emptyList)7 Collections.singletonList (java.util.Collections.singletonList)7 EventBus (io.cucumber.core.eventbus.EventBus)6 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)6 UUID (java.util.UUID)6 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)5 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)5 Clock (java.time.Clock)5 Arrays.asList (java.util.Arrays.asList)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)5 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)5 Glue (io.cucumber.core.backend.Glue)4