Search in sources :

Example 26 with RuntimeOptionsBuilder

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

the class PrettyFormatterTest method should_print_output_from_before_hooks.

@Test
void should_print_output_from_before_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(singletonList(new StubHookDefinition(testCaseState -> testCaseState.log("printed from hook"))), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), emptyList())).build().run();
    assertThat(out, bytesContainsString("" + "Scenario: scenario name # path/test.feature:2\n" + "\n" + "    printed from hook\n" + "\n" + "  Given first step      # path/step_definitions.java:3\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 27 with RuntimeOptionsBuilder

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

the class JsonParallelRuntimeTest method testSingleFeature.

@Test
void testSingleFeature() {
    ByteArrayOutputStream parallel = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).build()).withAdditionalPlugins(new JsonFormatter(parallel)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    ByteArrayOutputStream serial = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(1).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).build()).withAdditionalPlugins(new JsonFormatter(serial)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    assertThat(parallel.toString(), sameJSONAs(serial.toString()).allowingAnyArrayOrdering());
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 28 with RuntimeOptionsBuilder

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

the class JsonParallelRuntimeTest method testMultipleFeatures.

@Test
void testMultipleFeatures() {
    ByteArrayOutputStream parallel = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/FormatterInParallel.feature")).build()).withAdditionalPlugins(new JsonFormatter(parallel)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    ByteArrayOutputStream serial = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(1).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/FormatterInParallel.feature")).build()).withAdditionalPlugins(new JsonFormatter(serial)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    assertThat(parallel.toString(), sameJSONAs(serial.toString()).allowingAnyArrayOrdering());
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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