Search in sources :

Example 26 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class RuntimeTest 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 = TestHelper.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");
    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"));
    String formatterOutput = runFeatureWithFormatterSpy(feature, stepsToResult);
    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" + "done\n" + "close\n", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 27 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_failure_in_after_hook.

@Test
public void should_handle_failure_in_after_hook() throws Throwable {
    CucumberFeature feature = TestHelper.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, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("after", result("failed")));
    long stepHookDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, hooks, stepHookDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"1\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"0\" tests=\"1\" time=\"0.004\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.004\">\n" + "        <failure message=\"the stack trace\"><![CDATA[" + "Given first step............................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "\n" + "StackTrace:\n" + "the stack trace" + "]]></failure>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 28 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_format_scenario_outlines_with_arguments_in_name.

@Test
public void should_format_scenario_outlines_with_arguments_in_name() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario Outline: outline name <arg>\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");
    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=\"2\" time=\"0.006\">\n" + "    <testcase classname=\"feature name\" name=\"outline name a\" 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 b\" 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" + "</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 29 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_pending_in_before_hook.

@Test
public void should_handle_pending_in_before_hook() throws Throwable {
    CucumberFeature feature = TestHelper.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, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("skipped"));
    stepsToResult.put("second step", result("skipped"));
    stepsToResult.put("third step", result("skipped"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("pending")));
    long stepHookDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, hooks, stepHookDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"1\" tests=\"1\" time=\"0.001\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.001\">\n" + "        <skipped><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "]]></skipped>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 30 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_format_scenario_outlines.

@Test
public void should_format_scenario_outlines() 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\n" + "    | arg |\n" + "    |  a  |\n" + "    |  b  |\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=\"2\" time=\"0.006\">\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" + "</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)

Aggregations

Result (gherkin.formatter.model.Result)75 Test (org.junit.Test)58 CucumberFeature (cucumber.runtime.model.CucumberFeature)32 HashMap (java.util.HashMap)32 Reporter (gherkin.formatter.Reporter)11 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ArrayList (java.util.ArrayList)10 Match (gherkin.formatter.model.Match)9 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)8 Test (org.testng.annotations.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 PendingException (cucumber.api.PendingException)5 Matchers.anyString (org.mockito.Matchers.anyString)4 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)3 Scenario (gherkin.formatter.model.Scenario)3 List (java.util.List)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Given (cucumber.api.java.en.Given)2 DocString (gherkin.formatter.model.DocString)2