Search in sources :

Example 51 with CucumberFeature

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

the class TestNGFormatterTest method testScenarioWithUndefinedStepsStrict.

@Test
public void testScenarioWithUndefinedStepsStrict() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("undefined"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithStrictTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\">" + "                    <exception class=\"The scenario has pending or undefined step(s)\">" + "                        <message><![CDATA[When step...................................................................undefined\n" + "Then step...................................................................undefined\n" + "]]></message>" + "                        <full-stacktrace><![CDATA[The scenario has pending or undefined step(s)]]></full-stacktrace>" + "                    </exception>" + "                </test-method>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 52 with CucumberFeature

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

the class TestNGFormatterTest method testScenarioOutlineWithExamples.

@Test
public void testScenarioOutlineWithExamples() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario Outline: scenario\n" + "    When step\n" + "    Then step\n" + "    Examples:\n" + "    | arg |\n" + "    |  1  |\n" + "    |  2  |\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("undefined"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"2\" passed=\"0\" failed=\"0\" skipped=\"2\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"SKIP\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "                <test-method name=\"scenario_2\" status=\"SKIP\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 53 with CucumberFeature

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

the class TestNGFormatterTest method testScenarioWithFailedBeforeHook.

@Test
public void testScenarioWithFailedBeforeHook() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("skipped"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("failed", new TestNGException("message", "stacktrace"))));
    long stepHookDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, hooks, stepHookDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\">" + "                    <exception class=\"cucumber.runtime.formatter.TestNGFormatterTest$TestNGException\">" + "                        <message><![CDATA[When step...................................................................skipped\n" + "Then step...................................................................skipped\n" + "]]></message>" + "                        <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + "                    </exception>" + "                </test-method>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
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 54 with CucumberFeature

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

the class TestNGFormatterTest method testScenarioWithPassedSteps.

@Test
public final void testScenarioWithPassedSteps() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("passed"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"PASS\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 55 with CucumberFeature

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

the class TestNGFormatterTest method testDurationCalculationOfStepsAndHooks.

@Test
public void testDurationCalculationOfStepsAndHooks() throws Throwable {
    CucumberFeature feature1 = TestHelper.feature("path/feature1.feature", "" + "Feature: feature_1\n" + "  Scenario: scenario_1\n" + "    When step\n" + "    Then step\n" + "  Scenario: scenario_2\n" + "    When step\n" + "    Then step\n");
    CucumberFeature feature2 = TestHelper.feature("path/feature2.feature", "" + "Feature: feature_2\n" + "  Scenario: scenario_3\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("passed")));
    hooks.add(TestHelper.hookEntry("after", result("passed")));
    long stepHookDuration = milliSeconds(1);
    String actual = runFeaturesWithTestNGFormatter(Arrays.asList(feature1, feature2), stepsToResult, hooks, stepHookDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"3\" passed=\"3\" failed=\"0\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"12\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"12\">" + "            <class name=\"feature_1\">" + "                <test-method name=\"scenario_1\" status=\"PASS\" duration-ms=\"4\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "                <test-method name=\"scenario_2\" status=\"PASS\" duration-ms=\"4\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "            </class>" + "            <class name=\"feature_2\">" + "                <test-method name=\"scenario_3\" status=\"PASS\" duration-ms=\"4\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
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)

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