Skip to content

Commit

Permalink
Let JUnitFormatter handle PendingExceptions in hooks (#964)
Browse files Browse the repository at this point in the history
Merge #964 'Mark scenario as skipped in JUnitFormater if
PendingException is thrown in a hook'. Update History.md.
  • Loading branch information
brasmusson committed Feb 18, 2016
2 parents 6721eea + 6672352 commit 27e421b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [1.2.5-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.4...master) (In Git)

* [Core] Mark scenario as skipped in JUnitFormatter if PendingException is thrown in a hook ([#964](https://github.com/cucumber/cucumber-jvm/pull/964), [#962](https://github.com/cucumber/cucumber-jvm/issues/962) Felix Martin Martin)
* [Core] Support assume feature also with JUnit 4.12 ([#961](https://github.com/cucumber/cucumber-jvm/pull/961) Stefan Birkner)
* [TestNG] Always tear down TestNG cucumber tests ([#955](https://github.com/cucumber/cucumber-jvm/issues/955), [#956](https://github.com/cucumber/cucumber-jvm/pull/956) Sven-Torben Janus)
* [TestNG] Make TestNG to fail on unparseable feature files ([#953](https://github.com/cucumber/cucumber-jvm/issues/953) Björn Rasmusson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public void updateElement(Document doc, Element tc) {
}
for (Result result : hookResults) {
if (failed == null && "failed".equals(result.getStatus())) failed = result;
if (skipped == null && "pending".equals(result.getStatus())) skipped = result;
}
Element child;
if (failed != null) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/cucumber/runtime/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ private static void mockHook(SimpleEntry<String, Result> hookEntry, List<HookDef
when(hook.matches(anyCollectionOf(Tag.class))).thenReturn(true);
if (hookEntry.getValue().getStatus().equals("failed")) {
doThrow(hookEntry.getValue().getError()).when(hook).execute((cucumber.api.Scenario) any());
} else if (hookEntry.getValue().getStatus().equals("pending")) {
doThrow(new PendingException()).when(hook).execute((cucumber.api.Scenario) any());
}
if ("before".equals(hookEntry.getKey())) {
beforeHooks.add(hook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,37 @@ public void should_handle_failure_in_before_hook() throws Throwable {
"</testsuite>\n";
assertXmlEqual(expected, formatterOutput);
}

@Test
public void should_handle_pending_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("skipped"));
stepsToResult.put("second step", result("skipped"));
stepsToResult.put("third step", result("skipped"));
List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
hooks.add(TestHelper.hookEntry("before", result("pending")));
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=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"1\" tests=\"1\" time=\"0.001\">\n" +
" <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.001\">\n" +
" <skipped><![CDATA[" +
"Given first step............................................................skipped\n" +
"When second step............................................................skipped\n" +
"Then third step.............................................................skipped\n" +
"]]></skipped>\n" +
" </testcase>\n" +
"</testsuite>\n";
assertXmlEqual(expected, formatterOutput);
}

@Test
public void should_handle_failure_in_before_hook_with_background() throws Throwable {
Expand Down

0 comments on commit 27e421b

Please sign in to comment.