Search in sources :

Example 66 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_not_create_step_descriptions_by_default.

@Test
void should_not_create_step_descriptions_by_default() {
    Feature cucumberFeature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario: A\n" + "    Then scenario name\n" + "  Scenario: B\n" + "    Then scenario name\n" + "  Scenario Outline: C\n" + "    Then scenario <name>\n" + "  Examples:\n" + "    | name |\n" + "    | C    |\n" + "    | D    |\n" + "    | E    |\n");
    FeatureRunner runner = createFeatureRunner(cucumberFeature, new JUnitOptions());
    Description feature = runner.getDescription();
    Description scenarioA = feature.getChildren().get(0);
    assertTrue(scenarioA.getChildren().isEmpty());
    Description scenarioB = feature.getChildren().get(1);
    assertTrue(scenarioB.getChildren().isEmpty());
    Description scenarioC0 = feature.getChildren().get(2);
    assertTrue(scenarioC0.getChildren().isEmpty());
    Description scenarioC1 = feature.getChildren().get(3);
    assertTrue(scenarioC1.getChildren().isEmpty());
    Description scenarioC2 = feature.getChildren().get(4);
    assertTrue(scenarioC2.getChildren().isEmpty());
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 67 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method step_descriptions_can_be_turned_on.

@Test
void step_descriptions_can_be_turned_on() {
    Feature cucumberFeature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario: A\n" + "    Then scenario name\n" + "  Scenario: B\n" + "    Then scenario name\n" + "  Scenario Outline: C\n" + "    Then scenario <name>\n" + "  Examples:\n" + "    | name |\n" + "    | C    |\n" + "    | D    |\n" + "    | E    |\n");
    JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
    FeatureRunner runner = createFeatureRunner(cucumberFeature, junitOption);
    Description feature = runner.getDescription();
    Description scenarioA = feature.getChildren().get(0);
    assertThat(scenarioA.getChildren().size(), is(equalTo(2)));
    Description scenarioB = feature.getChildren().get(1);
    assertThat(scenarioB.getChildren().size(), is(equalTo(2)));
    Description scenarioC0 = feature.getChildren().get(2);
    assertThat(scenarioC0.getChildren().size(), is(equalTo(2)));
    Description scenarioC1 = feature.getChildren().get(3);
    assertThat(scenarioC1.getChildren().size(), is(equalTo(2)));
    Description scenarioC2 = feature.getChildren().get(4);
    assertThat(scenarioC2.getChildren().size(), is(equalTo(2)));
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 68 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_populate_descriptions_with_stable_unique_ids.

@Test
void should_populate_descriptions_with_stable_unique_ids() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario: A\n" + "    Then scenario name\n" + "  Scenario: B\n" + "    Then scenario name\n" + "  Scenario Outline: C\n" + "    Then scenario <name>\n" + "  Examples:\n" + "    | name |\n" + "    | C    |\n" + "    | D    |\n" + "    | E    |\n");
    FeatureRunner runner = createFeatureRunner(feature, new JUnitOptions());
    FeatureRunner rerunner = createFeatureRunner(feature, new JUnitOptions());
    Set<Description> descriptions = new HashSet<>();
    assertDescriptionIsUnique(runner.getDescription(), descriptions);
    assertDescriptionIsPredictable(runner.getDescription(), descriptions);
    assertDescriptionIsPredictable(rerunner.getDescription(), descriptions);
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 69 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background.

@Test
void step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given step #1\n" + "  Scenario Outline: scenario <id>\n" + "    When step #2 \n" + "    Then step #3 \n" + "    Examples: examples 1 name\n" + "      | id | \n" + "      | #1 |\n" + "      | #2  |\n" + "    Examples: examples 2 name\n" + "      | id |\n" + "      | #3 |\n");
    JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
    RunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #1")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #1")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #2")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #2")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #3")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #3")));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 70 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop.

@Test
void should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n");
    Filters filters = new Filters(RuntimeOptions.defaultOptions());
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    RuntimeOptions options = RuntimeOptions.defaultOptions();
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    RunNotifier notifier = mock(RunNotifier.class);
    PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
    featureRunner.runChild(pickleRunner, notifier);
    Description description = pickleRunner.getDescription();
    ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(description);
    order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
    assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
    assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
    order.verify(notifier).pleaseStop();
    order.verify(notifier).fireTestFinished(description);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) 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) Failure(org.junit.runner.notification.Failure) Test(org.junit.jupiter.api.Test)

Aggregations

Feature (io.cucumber.core.gherkin.Feature)152 Test (org.junit.jupiter.api.Test)144 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)92 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)77 UUID (java.util.UUID)67 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)59 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)23 Step (io.cucumber.core.gherkin.Step)22 StepDefinition (io.cucumber.core.backend.StepDefinition)21 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)21 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 DocString (io.cucumber.docstring.DocString)17 Executable (org.junit.jupiter.api.function.Executable)16 URI (java.net.URI)15 Arrays.asList (java.util.Arrays.asList)14 Collections.singletonList (java.util.Collections.singletonList)13