Search in sources :

Example 11 with CucumberFeature

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

the class FeatureRunnerTest method should_call_formatter_for_two_scenarios_with_background.

@Test
public void should_call_formatter_for_two_scenarios_with_background() throws Throwable {
    CucumberFeature cucumberFeature = TestFeatureBuilder.feature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given first step\n" + "  Scenario: scenario_1 name\n" + "    When second step\n" + "    Then third step\n" + "  Scenario: scenario_2 name\n" + "    Then second step\n");
    String formatterOutput = runFeatureWithFormatterSpy(cucumberFeature);
    assertEquals("" + "uri\n" + "feature\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" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "eof\n", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 12 with CucumberFeature

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

the class TestFeatureBuilder method feature.

static CucumberFeature feature(final String path, final String source) throws IOException {
    ArrayList<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    FeatureBuilder featureBuilder = new FeatureBuilder(cucumberFeatures);
    featureBuilder.parse(new Resource() {

        @Override
        public String getPath() {
            return path;
        }

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

        @Override
        public InputStream getInputStream() {
            try {
                return new ByteArrayInputStream(source.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getClassName(String extension) {
            throw new UnsupportedOperationException();
        }
    }, new ArrayList<Object>());
    featureBuilder.close();
    return cucumberFeatures.get(0);
}
Also used : FeatureBuilder(cucumber.runtime.FeatureBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CucumberFeature(cucumber.runtime.model.CucumberFeature) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with CucumberFeature

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

the class TestNGCucumberRunner method provideFeatures.

/**
     * @return returns the cucumber features as a two dimensional array of
     * {@link CucumberFeatureWrapper} objects.
     */
public Object[][] provideFeatures() {
    try {
        List<CucumberFeature> features = getFeatures();
        List<Object[]> featuresList = new ArrayList<Object[]>(features.size());
        for (CucumberFeature feature : features) {
            featuresList.add(new Object[] { new CucumberFeatureWrapperImpl(feature) });
        }
        return featuresList.toArray(new Object[][] {});
    } catch (CucumberException e) {
        return new Object[][] { new Object[] { new CucumberExceptionWrapper(e) } };
    }
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ArrayList(java.util.ArrayList) CucumberException(cucumber.runtime.CucumberException)

Example 14 with CucumberFeature

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

the class JUnitFormatterTest method should_format_scenario_outlines_with_multiple_examples.

@Test
public void should_format_scenario_outlines_with_multiple_examples() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario Outline: outline name\n" + "    Given first step \"<arg>\"\n" + "    When second step\n" + "    Then third step\n\n" + "  Examples: examples 1\n" + "    | arg |\n" + "    |  a  |\n" + "    |  b  |\n\n" + "  Examples: examples 2\n" + "    | arg |\n" + "    |  c  |\n" + "    |  d  |\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    long stepDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, stepDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"0\" tests=\"4\" time=\"0.012\">\n" + "    <testcase classname=\"feature name\" name=\"outline name\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"a\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 2\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"b\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 3\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"c\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 4\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"d\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 15 with CucumberFeature

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

the class TestHelper method feature.

public static CucumberFeature feature(final String path, final String source) throws IOException {
    ArrayList<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    FeatureBuilder featureBuilder = new FeatureBuilder(cucumberFeatures);
    featureBuilder.parse(new Resource() {

        @Override
        public String getPath() {
            return path;
        }

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

        @Override
        public InputStream getInputStream() {
            try {
                return new ByteArrayInputStream(source.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getClassName(String extension) {
            throw new UnsupportedOperationException();
        }
    }, new ArrayList<Object>());
    return cucumberFeatures.get(0);
}
Also used : Resource(cucumber.runtime.io.Resource) Matchers.anyString(org.mockito.Matchers.anyString) CucumberFeature(cucumber.runtime.model.CucumberFeature)

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