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);
}
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();
}
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);
}
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);
}
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));
}
Aggregations