Skip to content

Commit 42dccdf

Browse files
If an Exception is thrown during a @before hook, in the report, the scenario 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
1 parent 0f7daad commit 42dccdf

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

cucumber-formatter/src/test/java/at/porscheinformatik/cucumber/formatter/RpnCalculatorStepdefs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public void before()
5656
System.out.println("Runs before scenarios *not* tagged with @foo");
5757
}
5858

59+
@Before("@ExceptionOnBefore")
60+
public void beforeWithException() {
61+
throw new RuntimeException("Exception in @Before");
62+
}
63+
5964
@After
6065
public void after(Scenario scenario)
6166
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ExceptionOnBefore
2+
Feature: Check whether an exception in the before-hook doesn't mess up the report
3+
4+
Scenario: Simple Addition
5+
Given a calculator I just turned on
6+
When I add 4 and 5
7+
Then the result is 9

cucumber-report-web/src/main/resources/static/js/app.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
function getFailedScenarioCount(feature) {
2727
var failedScenarios = 0;
2828
feature.scenarios.forEach(function(scenario) {
29-
if(scenario.result.failedStepCount){
29+
if(scenario.result.failedStepCount || scenario.result.stepCount === scenario.result.skippedStepCount){
3030
failedScenarios++;
3131
}
3232
});
@@ -78,7 +78,13 @@
7878
step.result.searchKeyword = ":" + step.result.status + "Step";
7979
});
8080

81-
scenario.status = scenario.result.failedStepCount ? "failed" : (scenario.result.unknownStepCount ? 'unknown' : 'passed');
81+
if (scenario.result.failedStepCount || scenario.result.stepCount === scenario.result.skippedStepCount) {
82+
scenario.status = "failed";
83+
} else if (scenario.result.unknownStepCount) {
84+
scenario.status = 'unknown';
85+
} else {
86+
scenario.status = 'passed';
87+
}
8288
scenario.result.searchKeyword = ":" + scenario.status + "Scenario";
8389
});
8490

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

97-
if(isNaN(feature))
98-
{
99-
value = feature.result.duration;
100-
}
101-
else
102-
{
103+
if (!isNaN(feature)) {
103104
value = feature;
105+
} else if(feature.result.duration) {
106+
value = feature.result.duration;
104107
}
105108

106109
if(value<1000000000)

0 commit comments

Comments
 (0)