Search in sources :

Example 46 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class ExecutionUnitRunnerTest method shouldPopulateRunnerStepsWithStepsUsedInStepDescriptions.

@Test
public void shouldPopulateRunnerStepsWithStepsUsedInStepDescriptions() throws Exception {
    CucumberFeature cucumberFeature = TestFeatureBuilder.feature("featurePath", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario:\n" + "    Then scenario name\n");
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) cucumberFeature.getFeatureElements().get(0), createStandardJUnitReporter());
    // fish out the data from runner
    Description runnerDescription = runner.getDescription();
    Description backgroundStepDescription = runnerDescription.getChildren().get(0);
    Description scenarioStepDescription = runnerDescription.getChildren().get(1);
    Step runnerBackgroundStep = runner.getRunnerSteps().get(0);
    Step runnerScenarioStep = runner.getRunnerSteps().get(1);
    assertDescriptionHasStepAsUniqueId(backgroundStepDescription, runnerBackgroundStep);
    assertDescriptionHasStepAsUniqueId(scenarioStepDescription, runnerScenarioStep);
}
Also used : Description(org.junit.runner.Description) CucumberFeature(cucumber.runtime.model.CucumberFeature) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 47 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_call_formatter_for_scenario_outline_with_two_examples_table_and_background.

@Test
public void should_call_formatter_for_scenario_outline_with_two_examples_table_and_background() throws Throwable {
    CucumberFeature feature = TestFeatureBuilder.feature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given first step\n" + "  Scenario Outline: scenario outline name\n" + "    When <x> step\n" + "    Then <y> step\n" + "    Examples: examples 1 name\n" + "      |   x    |   y   |\n" + "      | second | third |\n" + "      | second | third |\n" + "    Examples: examples 2 name\n" + "      |   x    |   y   |\n" + "      | second | third |\n");
    String formatterOutput = runFeatureWithFormatterSpy(feature);
    assertEquals("" + "uri\n" + "feature\n" + "  scenarioOutline\n" + "    step\n" + "    step\n" + "  examples\n" + "  startOfScenarioLifeCycle\n" + "  background\n" + "    step\n" + "    match\n" + "    result\n" + "  scenario\n" + "    step\n" + "    step\n" + "    match\n" + "    result\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "  startOfScenarioLifeCycle\n" + "  background\n" + "    step\n" + "    match\n" + "    result\n" + "  scenario\n" + "    step\n" + "    step\n" + "    match\n" + "    result\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "  examples\n" + "  startOfScenarioLifeCycle\n" + "  background\n" + "    step\n" + "    match\n" + "    result\n" + "  scenario\n" + "    step\n" + "    step\n" + "    match\n" + "    result\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "eof\n", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 48 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class StepdefGeneratorTest method features.

private List<CucumberFeature> features() throws IOException {
    List<CucumberFeature> features = new ArrayList<CucumberFeature>();
    FeatureBuilder fb = new FeatureBuilder(features);
    fb.parse(new Resource() {

        @Override
        public String getPath() {
            return "test.feature";
        }

        @Override
        public String getAbsolutePath() {
            throw new UnsupportedOperationException();
        }

        @Override
        public InputStream getInputStream() {
            try {
                return new ByteArrayInputStream(("" + "Feature: Test\n" + "  Scenario: Test\n" + "    Given I have 4 cukes in my belly\n" + "    And I have 3 bananas in my basket\n" + "    Given I have 42 cukes in my belly\n").getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getClassName(String extension) {
            throw new UnsupportedOperationException();
        }
    }, emptyList());
    return features;
}
Also used : FeatureBuilder(cucumber.runtime.FeatureBuilder) CucumberFeature(cucumber.runtime.model.CucumberFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 49 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class CucumberPrettyFormatterTest method should_align_the_indentation_of_location_strings.

@Test
public void should_align_the_indentation_of_location_strings() throws Throwable {
    CucumberFeature feature = feature("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, String> stepsToLocation = new HashMap<String, String>();
    stepsToLocation.put("first step", "path/step_definitions.java:3");
    stepsToLocation.put("second step", "path/step_definitions.java:7");
    stepsToLocation.put("third step", "path/step_definitions.java:11");
    String formatterOutput = runFeatureWithPrettyFormatter(feature, stepsToLocation);
    assertThat(formatterOutput, containsString("  Scenario: scenario name # path/test.feature:2\n" + "    Given first step      # path/step_definitions.java:3\n" + "    When second step      # path/step_definitions.java:7\n" + "    Then third step       # path/step_definitions.java:11\n"));
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 50 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class TestHelper method runFeaturesWithFormatter.

private static void runFeaturesWithFormatter(final List<CucumberFeature> features, final Map<String, Result> stepsToResult, final Map<String, String> stepsToLocation, final List<SimpleEntry<String, Result>> hooks, final long stepHookDuration, final Formatter formatter, final Reporter reporter) throws Throwable {
    final RuntimeOptions runtimeOptions = new RuntimeOptions("");
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
    final RuntimeGlue glue = createMockedRuntimeGlueThatMatchesTheSteps(stepsToResult, stepsToLocation, hooks);
    final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions, new StopWatch.Stub(stepHookDuration), glue);
    for (CucumberFeature feature : features) {
        feature.run(formatter, reporter, runtime);
    }
    formatter.done();
    formatter.close();
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader)

Aggregations

CucumberFeature (cucumber.runtime.model.CucumberFeature)65 Test (org.junit.Test)53 HashMap (java.util.HashMap)33 Result (gherkin.formatter.model.Result)32 ArrayList (java.util.ArrayList)19 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)6 Resource (cucumber.runtime.io.Resource)6 Formatter (gherkin.formatter.Formatter)5 Reporter (gherkin.formatter.Reporter)5 StepDefinitionReporter (cucumber.api.StepDefinitionReporter)4 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)4 Step (gherkin.formatter.model.Step)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CucumberJSONFormatter (cucumber.runtime.formatter.CucumberJSONFormatter)3 JSONFormatter (gherkin.formatter.JSONFormatter)3 Tag (gherkin.formatter.model.Tag)3 Description (org.junit.runner.Description)3 Scenario (cucumber.api.Scenario)2