Skip to content

Commit

Permalink
If an Exception is thrown during a @before hook, in the report, the s…
Browse files Browse the repository at this point in the history
…cenario is displayed as "passed" #34

* fixes calculation of duration and failedStepCounts in features-overview
* mark scenarios as failed when exceptions in @before hook is thrown
  • Loading branch information
klausbayrhammer committed Jun 28, 2015
1 parent 0f7daad commit 42dccdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void before()
System.out.println("Runs before scenarios *not* tagged with @foo");
}

@Before("@ExceptionOnBefore")
public void beforeWithException() {
throw new RuntimeException("Exception in @Before");
}

@After
public void after(Scenario scenario)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ExceptionOnBefore
Feature: Check whether an exception in the before-hook doesn't mess up the report

Scenario: Simple Addition
Given a calculator I just turned on
When I add 4 and 5
Then the result is 9
19 changes: 11 additions & 8 deletions cucumber-report-web/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
function getFailedScenarioCount(feature) {
var failedScenarios = 0;
feature.scenarios.forEach(function(scenario) {
if(scenario.result.failedStepCount){
if(scenario.result.failedStepCount || scenario.result.stepCount === scenario.result.skippedStepCount){
failedScenarios++;
}
});
Expand Down Expand Up @@ -78,7 +78,13 @@
step.result.searchKeyword = ":" + step.result.status + "Step";
});

scenario.status = scenario.result.failedStepCount ? "failed" : (scenario.result.unknownStepCount ? 'unknown' : 'passed');
if (scenario.result.failedStepCount || scenario.result.stepCount === scenario.result.skippedStepCount) {
scenario.status = "failed";
} else if (scenario.result.unknownStepCount) {
scenario.status = 'unknown';
} else {
scenario.status = 'passed';
}
scenario.result.searchKeyword = ":" + scenario.status + "Scenario";
});

Expand All @@ -94,13 +100,10 @@
data.duration = function(feature){
var value=0;

if(isNaN(feature))
{
value = feature.result.duration;
}
else
{
if (!isNaN(feature)) {
value = feature;
} else if(feature.result.duration) {
value = feature.result.duration;
}

if(value<1000000000)
Expand Down

0 comments on commit 42dccdf

Please sign in to comment.