Search in sources :

Example 6 with Result

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

the class TestNGFormatterTest method testScenarioWithFailedAfterHook.

@Test
public void testScenarioWithFailedAfterHook() 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"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("after", 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...................................................................passed\n" + "Then step...................................................................passed\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 7 with Result

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

the class TestNGFormatterTest method runFeatureWithStrictTestNGFormatter.

private String runFeatureWithStrictTestNGFormatter(CucumberFeature feature, Map<String, Result> stepsToResult, long stepDuration) throws IOException, Throwable, FileNotFoundException {
    final File tempFile = File.createTempFile("cucumber-jvm-testng", ".xml");
    final TestNGFormatter formatter = new TestNGFormatter(toURL(tempFile.getAbsolutePath()));
    formatter.setStrict(true);
    TestHelper.runFeatureWithFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), stepDuration, formatter, formatter);
    return new Scanner(new FileInputStream(tempFile), "UTF-8").useDelimiter("\\A").next();
}
Also used : Scanner(java.util.Scanner) File(java.io.File) FileInputStream(java.io.FileInputStream) Result(gherkin.formatter.model.Result)

Example 8 with Result

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

the class TestNGFormatterTest method testScenarioWithUndefinedSteps.

@Test
public final void testScenarioWithUndefinedSteps() 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 = runFeatureWithTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"0\" skipped=\"1\">" + "    <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\"/>" + "            </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 9 with Result

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

the class UsageFormatterTest method resultWithNullDuration.

@Test
public void resultWithNullDuration() {
    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(null);
    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 10 with Result

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

the class UsageFormatterTest method resultWithStep.

@Test
public void resultWithStep() {
    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(12345L);
    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.valueOf(12345));
}
Also used : List(java.util.List) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) 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