use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.
the class Runtime method runStep.
public void runStep(String featurePath, Step step, Reporter reporter, I18n i18n) {
StepDefinitionMatch match;
try {
match = glue.stepDefinitionMatch(featurePath, step, i18n);
} catch (AmbiguousStepDefinitionsException e) {
reporter.match(e.getMatches().get(0));
Result result = new Result(Result.FAILED, 0L, e, DUMMY_ARG);
reporter.result(result);
addStepToCounterAndResult(result);
addError(e);
skipNextStep = true;
return;
}
if (match != null) {
reporter.match(match);
} else {
reporter.match(Match.UNDEFINED);
reporter.result(Result.UNDEFINED);
addStepToCounterAndResult(Result.UNDEFINED);
skipNextStep = true;
return;
}
if (runtimeOptions.isDryRun()) {
skipNextStep = true;
}
if (skipNextStep) {
addStepToCounterAndResult(Result.SKIPPED);
reporter.result(Result.SKIPPED);
} else {
String status = Result.PASSED;
Throwable error = null;
stopWatch.start();
try {
match.runStep(i18n);
} catch (Throwable t) {
error = t;
status = isPending(t) ? "pending" : Result.FAILED;
addError(t);
skipNextStep = true;
} finally {
long duration = stopWatch.stop();
Result result = new Result(status, duration, error, DUMMY_ARG);
addStepToCounterAndResult(result);
reporter.result(result);
}
}
}
use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method should_format_scenario_outlines_with_multiple_examples.
@Test
public void should_format_scenario_outlines_with_multiple_examples() 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 1\n" + " | arg |\n" + " | a |\n" + " | b |\n\n" + " Examples: examples 2\n" + " | arg |\n" + " | c |\n" + " | d |\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=\"4\" time=\"0.012\">\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" + " <testcase classname=\"feature name\" name=\"outline name 3\" time=\"0.003\">\n" + " <system-out><![CDATA[" + "Given first step \"c\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + " <testcase classname=\"feature name\" name=\"outline name 4\" time=\"0.003\">\n" + " <system-out><![CDATA[" + "Given first step \"d\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + "</testsuite>\n";
assertXmlEqual(expected, formatterOutput);
}
use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithBackground.
@Test
public void testScenarioWithBackground() throws Throwable {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + " Background:\n" + " When background\n" + " Then background\n" + " Scenario: scenario\n" + " When step\n" + " Then step\n");
Map<String, Result> stepsToResult = new HashMap<String, Result>();
stepsToResult.put("background", result("undefined"));
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 TestNGFormatterTest method testScenarioWithFailedSteps.
@Test
public void testScenarioWithFailedSteps() throws Throwable {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + " Scenario: scenario\n" + " When step1\n" + " Then step2\n");
Map<String, Result> stepsToResult = new HashMap<String, Result>();
stepsToResult.put("step1", result("failed", new TestNGException("message", "stacktrace")));
stepsToResult.put("step2", result("skipped"));
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=\"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 step1..................................................................failed\n" + "Then step2..................................................................skipped\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 testScenarioWithPendingSteps.
@Test
public final void testScenarioWithPendingSteps() throws Throwable {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + " Scenario: scenario\n" + " When step1\n" + " Then step2\n");
Map<String, Result> stepsToResult = new HashMap<String, Result>();
stepsToResult.put("step1", result("pending"));
stepsToResult.put("step2", result("skipped"));
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);
}
Aggregations