Search in sources :

Example 6 with CucumberFeature

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

the class FormatterMissingLifecycleMethods method handles_formatters_missing_startOfScenarioLifeCycle_endOfScenarioLifeCycle.

@Test
public void handles_formatters_missing_startOfScenarioLifeCycle_endOfScenarioLifeCycle() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given step\n");
    FormatterSpy formatterSpy = new FormatterSpy();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    runtimeOptions.addPlugin(new FormatterMissingLifecycleMethods());
    runtimeOptions.addPlugin(formatterSpy);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    TestHelper.runFeatureWithFormatter(feature, new HashMap<String, String>(), runtimeOptions.formatter(classLoader), runtimeOptions.reporter(classLoader));
    assertEquals("" + "uri\n" + "feature\n" + "  startOfScenarioLifeCycle\n" + "  scenario\n" + "    step\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "eof\n" + "done\n" + "close\n", formatterSpy.toString());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) FormatterSpy(cucumber.runtime.formatter.FormatterSpy) Test(org.junit.Test)

Example 7 with CucumberFeature

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

the class FormatterMissingLifecycleMethods method applies_line_filters_only_to_own_feature.

@Test
public void applies_line_filters_only_to_own_feature() throws Exception {
    String featurePath1 = "path/bar.feature";
    String feature1 = "" + "Feature: bar\n" + "  Scenario: scenario_1_1\n" + "    * step\n" + "  Scenario: scenario_1_2\n" + "    * step\n";
    String featurePath2 = "path/foo.feature";
    String feature2 = "" + "Feature: foo\n" + "  Scenario: scenario_2_1\n" + "    * step\n" + "  Scenario: scenario_2_2\n" + "    * step\n";
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    mockResource(resourceLoader, featurePath1, feature1);
    mockResource(resourceLoader, featurePath2, feature2);
    RuntimeOptions options = new RuntimeOptions(featurePath1 + ":2 " + featurePath2 + ":4");
    List<CucumberFeature> features = options.cucumberFeatures(resourceLoader);
    assertEquals(2, features.size());
    assertOnlyScenarioName(features.get(0), "scenario_1_1");
    assertOnlyScenarioName(features.get(1), "scenario_2_2");
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 8 with CucumberFeature

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

the class Runtime method run.

/**
     * This is the main entry point. Used from CLI, but not from JUnit.
     */
public void run() throws IOException {
    // Make sure all features parse before initialising any reporters/formatters
    List<CucumberFeature> features = runtimeOptions.cucumberFeatures(resourceLoader);
    // TODO: This is duplicated in cucumber.api.android.CucumberInstrumentationCore - refactor or keep uptodate
    Formatter formatter = runtimeOptions.formatter(classLoader);
    Reporter reporter = runtimeOptions.reporter(classLoader);
    StepDefinitionReporter stepDefinitionReporter = runtimeOptions.stepDefinitionReporter(classLoader);
    glue.reportStepDefinitions(stepDefinitionReporter);
    for (CucumberFeature cucumberFeature : features) {
        cucumberFeature.run(formatter, reporter, this);
    }
    formatter.done();
    formatter.close();
    printSummary();
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Formatter(gherkin.formatter.Formatter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter) Reporter(gherkin.formatter.Reporter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter)

Example 9 with CucumberFeature

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

the class ExecutionUnitRunnerTest method shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario.

@Test
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
    List<CucumberFeature> features = CucumberFeature.load(new ClasspathResourceLoader(this.getClass().getClassLoader()), asList("cucumber/runtime/junit/fb.feature"), Collections.emptyList());
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) features.get(0).getFeatureElements().get(0), createStandardJUnitReporter());
    // fish out the two occurrences of the same step and check whether we really got them
    Step stepOccurrence1 = runner.getChildren().get(0);
    Step stepOccurrence2 = runner.getChildren().get(2);
    assertEquals(stepOccurrence1.getName(), stepOccurrence2.getName());
    // then check that the descriptions are unequal
    Description runnerDescription = runner.getDescription();
    Description stepDescription1 = runnerDescription.getChildren().get(0);
    Description stepDescription2 = runnerDescription.getChildren().get(2);
    assertFalse("Descriptions must not be equal.", stepDescription1.equals(stepDescription2));
}
Also used : Description(org.junit.runner.Description) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 10 with CucumberFeature

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

the class ExecutionUnitRunnerTest method shouldConvertTextFromFeatureFileForNamesWithFilenameCompatibleNameOption.

@Test
public void shouldConvertTextFromFeatureFileForNamesWithFilenameCompatibleNameOption() throws Exception {
    CucumberFeature cucumberFeature = TestFeatureBuilder.feature("featurePath", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Then it works\n");
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) cucumberFeature.getFeatureElements().get(0), createJUnitReporterWithOption("--filename-compatible-names"));
    assertEquals("Scenario__scenario_name", runner.getName());
    assertEquals("Then_it_works", runner.getDescription().getChildren().get(0).getMethodName());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Aggregations

CucumberFeature (cucumber.runtime.model.CucumberFeature)64 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 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 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)3 JSONFormatter (gherkin.formatter.JSONFormatter)3 Tag (gherkin.formatter.model.Tag)3 Description (org.junit.runner.Description)3 Scenario (cucumber.api.Scenario)2