Search in sources :

Example 61 with Result

use of gherkin.formatter.model.Result 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 62 with Result

use of gherkin.formatter.model.Result 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)

Example 63 with Result

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

the class UsageFormatterTest method resultWithoutSkippedSteps.

@Test
public void resultWithoutSkippedSteps() {
    Appendable out = mock(Appendable.class);
    UsageFormatter usageFormatter = new UsageFormatter(out);
    Result result = mock(Result.class);
    when(result.getStatus()).thenReturn(Result.SKIPPED.getStatus());
    usageFormatter.result(result);
    verifyZeroInteractions(out);
}
Also used : Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 64 with Result

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

the class UsageFormatterTest method resultWithZeroDuration.

@Test
public void resultWithZeroDuration() {
    Appendable out = mock(Appendable.class);
    UsageFormatter usageFormatter = new UsageFormatter(out);
    StepDefinitionMatch match = mockStepDefinitionMatch();
    usageFormatter.match(match);
    Result result = mock(Result.class);
    when(result.getDuration()).thenReturn(0L);
    when(result.getStatus()).thenReturn(Result.PASSED);
    usageFormatter.result(result);
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertEquals(usageMap.size(), 1);
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertEquals(durationEntries.size(), 1);
    assertEquals(durationEntries.get(0).name, "step");
    assertEquals(durationEntries.get(0).durations.size(), 1);
    assertEquals(durationEntries.get(0).durations.get(0).duration, BigDecimal.ZERO);
}
Also used : List(java.util.List) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 65 with Result

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

the class JUnitFormatterTest method should_handle_failure_in_before_hook.

@Test
public void should_handle_failure_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("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("before", 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.001\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.001\">\n" + "        <failure message=\"the stack trace\"><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\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)

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