Skip to content

Commit 515466e

Browse files
committed
Only include executed scenarios and steps in the JSON output
Do not include the Scenario Outline and Examples given as information before the execution of the instantiated scenarios from the outline. This unified the JSON output from Cucumber-JVM regardless of the feature is executed by the command line runner, the JUnit runner of the TestNG runner. The JUnit runner differs from the other by not sending the Scenario Outline and Examples as information to the formatters before executing the instantiated scenarios from the outline, so this commit only affects the output from the command line runner and the TestNG runner.
1 parent 08e6b87 commit 515466e

File tree

4 files changed

+41
-66
lines changed

4 files changed

+41
-66
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cucumber.runtime.formatter;
2+
3+
import gherkin.formatter.JSONFormatter;
4+
import gherkin.formatter.model.Examples;
5+
import gherkin.formatter.model.Scenario;
6+
import gherkin.formatter.model.ScenarioOutline;
7+
import gherkin.formatter.model.Step;
8+
9+
public class CucumberJSONFormatter extends JSONFormatter {
10+
private boolean inScenarioOutline = false;
11+
12+
public CucumberJSONFormatter(Appendable out) {
13+
super(out);
14+
}
15+
16+
@Override
17+
public void scenarioOutline(ScenarioOutline scenarioOutline) {
18+
inScenarioOutline = true;
19+
}
20+
21+
@Override
22+
public void examples(Examples examples) {
23+
// NoOp
24+
}
25+
26+
@Override
27+
public void startOfScenarioLifeCycle(Scenario scenario) {
28+
inScenarioOutline = false;
29+
super.startOfScenarioLifeCycle(scenario);
30+
}
31+
32+
@Override
33+
public void step(Step step) {
34+
if (!inScenarioOutline) {
35+
super.step(step);
36+
}
37+
}
38+
}

core/src/main/java/cucumber/runtime/formatter/FormatterFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import cucumber.runtime.io.URLOutputStream;
55
import cucumber.runtime.io.UTF8OutputStreamWriter;
66
import gherkin.formatter.Formatter;
7-
import gherkin.formatter.JSONFormatter;
87

98
import java.io.File;
109
import java.io.IOException;
@@ -37,7 +36,7 @@ public class FormatterFactory {
3736
put("html", HTMLFormatter.class);
3837
put("pretty", CucumberPrettyFormatter.class);
3938
put("progress", ProgressFormatter.class);
40-
put("json", JSONFormatter.class);
39+
put("json", CucumberJSONFormatter.class);
4140
put("usage", UsageFormatter.class);
4241
put("rerun", RerunFormatter.class);
4342
}};

core/src/test/java/cucumber/runtime/RuntimeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cucumber.api.PendingException;
44
import cucumber.api.Scenario;
5+
import cucumber.runtime.formatter.CucumberJSONFormatter;
56
import cucumber.runtime.io.ClasspathResourceLoader;
67
import cucumber.runtime.io.Resource;
78
import cucumber.runtime.io.ResourceLoader;
@@ -51,7 +52,7 @@ public void runs_feature_with_json_formatter() throws Exception {
5152
" Scenario: scenario name\n" +
5253
" When s\n");
5354
StringBuilder out = new StringBuilder();
54-
JSONFormatter jsonFormatter = new JSONFormatter(out);
55+
JSONFormatter jsonFormatter = new CucumberJSONFormatter(out);
5556
List<Backend> backends = asList(mock(Backend.class));
5657
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
5758
RuntimeOptions runtimeOptions = new RuntimeOptions("");

core/src/test/resources/cucumber/runtime/formatter/JSONPrettyFormatterTest.json

-63
Original file line numberDiff line numberDiff line change
@@ -97,69 +97,6 @@
9797
],
9898
"type": "scenario"
9999
},
100-
{
101-
"id": "feature-3;scenariooutline-1",
102-
"description": "",
103-
"name": "ScenarioOutline_1",
104-
"keyword": "Scenario Outline",
105-
"line": 14,
106-
"steps": [
107-
{
108-
"name": "so_1 \u003ca\u003e",
109-
"keyword": "Given ",
110-
"line": 15
111-
},
112-
{
113-
"name": "so_2 \u003cc\u003e cucumbers",
114-
"keyword": "When ",
115-
"line": 16
116-
},
117-
{
118-
"name": "\u003cb\u003e so_3",
119-
"keyword": "Then ",
120-
"line": 17
121-
}
122-
],
123-
"examples": [
124-
{
125-
"id": "feature-3;scenariooutline-1;",
126-
"description": "",
127-
"name": "",
128-
"keyword": "Examples",
129-
"line": 19,
130-
"rows": [
131-
{
132-
"id": "feature-3;scenariooutline-1;;1",
133-
"cells": [
134-
"a",
135-
"b",
136-
"c"
137-
],
138-
"line": 20
139-
},
140-
{
141-
"id": "feature-3;scenariooutline-1;;2",
142-
"cells": [
143-
"12",
144-
"5",
145-
"7"
146-
],
147-
"line": 21
148-
},
149-
{
150-
"id": "feature-3;scenariooutline-1;;3",
151-
"cells": [
152-
"20",
153-
"5",
154-
"15"
155-
],
156-
"line": 22
157-
}
158-
]
159-
}
160-
],
161-
"type": "scenario_outline"
162-
},
163100
{
164101
"description": "",
165102
"name": "",

0 commit comments

Comments
 (0)