Search in sources :

Example 36 with StubBackendSupplier

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

the class RerunFormatterTest method should_use_scenario_location_when_before_hook_fails.

@Test
void should_use_scenario_location_when_before_hook_fails() {
    Feature feature = TestFeatureParser.parse("classpath: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 RerunFormatter(out)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition(new StubException())), asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), emptyList())).build().run();
    assertThat(out, isBytesEqualTo("classpath:path/test.feature:2\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 37 with StubBackendSupplier

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

the class RerunFormatterTest method should_put_data_in_report_when_exit_code_is_non_zero.

@Test
void should_put_data_in_report_when_exit_code_is_non_zero() {
    Feature feature = TestFeatureParser.parse("classpath:path/test.feature", "" + "Feature: feature name\n" + "  Scenario: failed scenario\n" + "    Given failed step\n" + "  Scenario: pending scenario\n" + "    Given pending step\n" + "  Scenario: undefined scenario\n" + "    Given undefined step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new RerunFormatter(out)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("failed step", new StubException()), new StubStepDefinition("pending step", new StubPendingException()))).build().run();
    assertThat(out, isBytesEqualTo("classpath:path/test.feature:2:4:6\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubPendingException(io.cucumber.core.backend.StubPendingException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 38 with StubBackendSupplier

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

the class TeamCityPluginTest method should_handle_write_events.

@Test
void should_handle_write_events() {
    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 TeamCityPlugin(new PrintStream(out))).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition((TestCaseState state) -> state.log("A message"))), singletonList(new StubStepDefinition("first step")), emptyList())).build().run();
    assertThat(out, bytesContainsString("" + "##teamcity[message text='Write event:|nA message|n' status='NORMAL']\n"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) PrintStream(java.io.PrintStream) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) TestCaseState(io.cucumber.core.backend.TestCaseState) Test(org.junit.jupiter.api.Test)

Example 39 with StubBackendSupplier

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

the class RerunFormatterTest method should_use_scenario_location_when_after_hook_fails.

@Test
void should_use_scenario_location_when_after_hook_fails() {
    Feature feature = TestFeatureParser.parse("classpath: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 RerunFormatter(out)).withBackendSupplier(new StubBackendSupplier(emptyList(), asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), singletonList(new StubHookDefinition(new StubException())))).build().run();
    assertThat(out, isBytesEqualTo("classpath:path/test.feature:2\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 40 with StubBackendSupplier

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

the class RerunFormatterTest method should_use_scenario_location_when_background_step_fails.

@Test
void should_use_scenario_location_when_background_step_fails() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Background: the background\n" + "    Given background step\n" + "  Scenario: scenario name\n" + "    When second step\n" + "    Then third step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new RerunFormatter(out)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("background step", new StubException()), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
    assertThat(out, isBytesEqualTo("file:path/test.feature:4\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) 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)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