Search in sources :

Example 21 with RuntimeOptionsBuilder

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

the class DryRunTest method dry_run_passes_skipped_step.

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

Example 22 with RuntimeOptionsBuilder

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

the class DryRunTest method dry_run_passes_failed_step.

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

Example 23 with RuntimeOptionsBuilder

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

the class CompatibilityTest method produces_expected_output_for.

@ParameterizedTest
@MethodSource("io.cucumber.compatibility.TestCase#testCases")
void produces_expected_output_for(TestCase testCase) throws IOException {
    Path parentDir = Files.createDirectories(Paths.get("target", "messages", testCase.getId()));
    Path outputNdjson = parentDir.resolve("out.ndjson");
    Path outputHtml = parentDir.resolve("out.html");
    Path outputJson = parentDir.resolve("out.json");
    try {
        Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().addGlue(testCase.getGlue()).addFeature(testCase.getFeature()).build()).withAdditionalPlugins(new MessageFormatter(newOutputStream(outputNdjson)), new HtmlFormatter(newOutputStream(outputHtml)), new JsonFormatter(newOutputStream(outputJson))).build().run();
    } catch (Exception ignored) {
    }
    List<JsonNode> expected = readAllMessages(testCase.getExpectedFile());
    List<JsonNode> actual = readAllMessages(outputNdjson);
    Map<String, List<JsonNode>> expectedEnvelopes = openEnvelopes(expected);
    Map<String, List<JsonNode>> actualEnvelopes = openEnvelopes(actual);
    // exception: Java step definitions are not in a predictable order
    // because Class#getMethods() does not return a predictable order.
    sortStepDefinitions(expectedEnvelopes);
    sortStepDefinitions(actualEnvelopes);
    // unknown-parameter-types
    if ("unknown-parameter-type".equals(testCase.getId())) {
        expectedEnvelopes.remove("testCase");
        expectedEnvelopes.remove("testCaseStarted");
        expectedEnvelopes.remove("testStepStarted");
        expectedEnvelopes.remove("testStepFinished");
        expectedEnvelopes.remove("testCaseFinished");
    }
    expectedEnvelopes.forEach((messageType, expectedMessages) -> assertThat(actualEnvelopes, hasEntry(is(messageType), containsInRelativeOrder(aComparableMessage(expectedMessages)))));
}
Also used : Path(java.nio.file.Path) JsonFormatter(io.cucumber.core.plugin.JsonFormatter) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) JsonNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) MessageFormatter(io.cucumber.core.plugin.MessageFormatter) HtmlFormatter(io.cucumber.core.plugin.HtmlFormatter) JsonProcessingException(io.cucumber.messages.internal.com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 24 with RuntimeOptionsBuilder

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

the class FeatureRunnerTest method should_filter_pickles.

@Test
void should_filter_pickles() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n" + "  @tag\n" + "  Scenario: scenario_2 name\n" + "    Given step #1\n");
    RuntimeOptions options = new RuntimeOptionsBuilder().addTagFilter(TagExpressionParser.parse("@tag")).build();
    Filters filters = new Filters(options);
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    assertThat(featureRunner.getChildren().size(), is(1));
    assertThat(featureRunner.getChildren().get(0).getDescription().getDisplayName(), is("scenario_2 name(feature name)"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 25 with RuntimeOptionsBuilder

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

the class PrettyFormatterTest method should_skip_missing_location_strings.

@Test
void should_skip_missing_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", (String) null), 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\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)

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