Search in sources :

Example 71 with Feature

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

the class FeatureRunnerTest method should_not_issue_notification_for_steps_by_default_two_scenarios_with_background.

@Test
void should_not_issue_notification_for_steps_by_default_two_scenarios_with_background() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given step #1\n" + "  Scenario: scenario_1 name\n" + "    When step #2\n" + "    Then step #3\n" + "  Scenario: scenario_2 name\n" + "    Then step #2\n");
    RunNotifier notifier = runFeatureWithNotifier(feature, new JUnitOptions());
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
    order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario_1 name(feature name)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
    order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario_2 name(feature name)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
}
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 72 with Feature

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

the class JavaSnippetTest method createStep.

private Step createStep(String stepText) {
    String source = "" + "Feature: Test feature\n" + "  Scenario: Test Scenario\n" + "    Given " + stepText + "\n";
    Feature feature = TestFeatureParser.parse(source);
    return feature.getPickles().get(0).getSteps().get(0);
}
Also used : Feature(io.cucumber.core.gherkin.Feature)

Example 73 with Feature

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

the class FeaturePathFeatureSupplier method loadFeatures.

private List<Feature> loadFeatures(List<URI> featurePaths) {
    log.debug(() -> "Loading features from " + featurePaths.stream().map(URI::toString).collect(joining(", ")));
    final FeatureBuilder builder = new FeatureBuilder();
    for (URI featurePath : featurePaths) {
        List<Feature> found = featureScanner.scanForResourcesUri(featurePath);
        if (found.isEmpty() && isFeature(featurePath)) {
            throw new IllegalArgumentException("Feature not found: " + featurePath);
        }
        found.forEach(builder::addUnique);
    }
    return builder.build();
}
Also used : URI(java.net.URI) Feature(io.cucumber.core.gherkin.Feature) FeatureIdentifier.isFeature(io.cucumber.core.feature.FeatureIdentifier.isFeature)

Example 74 with Feature

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

the class FeatureParserTest method feature_file_without_pickles_is_parsed_produces_empty_feature.

@Test
void feature_file_without_pickles_is_parsed_produces_empty_feature() throws IOException {
    URI uri = URI.create("classpath:com/example.feature");
    String source = new String(readAllBytes(Paths.get("src/test/resources/io/cucumber/core/gherkin/messages/no-pickles.feature")));
    Optional<Feature> feature = parser.parse(uri, source, UUID::randomUUID);
    assertTrue(feature.isPresent());
    assertEquals(0, feature.get().getPickles().size());
}
Also used : UUID(java.util.UUID) URI(java.net.URI) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 75 with Feature

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

the class FeatureParserTest method unnamed_elements_return_empty_strings_as_name.

@Test
void unnamed_elements_return_empty_strings_as_name() throws IOException {
    URI uri = URI.create("classpath:com/example.feature");
    String source = new String(readAllBytes(Paths.get("src/test/resources/io/cucumber/core/gherkin/messages/unnamed.feature")));
    Feature feature = parser.parse(uri, source, UUID::randomUUID).get();
    assertEquals(Optional.empty(), feature.getName());
    Node.Rule rule = (Node.Rule) feature.elements().iterator().next();
    assertEquals(Optional.empty(), rule.getName());
    assertEquals(Optional.of("Rule"), rule.getKeyword());
    Iterator<Node> ruleElements = rule.elements().iterator();
    Node.Scenario scenario = (Node.Scenario) ruleElements.next();
    assertEquals(Optional.empty(), scenario.getName());
    assertEquals(Optional.of("Scenario"), scenario.getKeyword());
    Node.ScenarioOutline scenarioOutline = (Node.ScenarioOutline) ruleElements.next();
    assertEquals(Optional.empty(), scenarioOutline.getName());
    assertEquals(Optional.of("Scenario Outline"), scenarioOutline.getKeyword());
    Node.Examples examples = scenarioOutline.elements().iterator().next();
    assertEquals(Optional.empty(), examples.getName());
    assertEquals(Optional.of("Examples"), examples.getKeyword());
    Node.Example example = examples.elements().iterator().next();
    // Example is the exception.
    assertEquals(Optional.of("Example #1"), example.getName());
    assertEquals(Optional.empty(), example.getKeyword());
}
Also used : Node(io.cucumber.plugin.event.Node) URI(java.net.URI) Feature(io.cucumber.core.gherkin.Feature) 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