Skip to content

Commit 8e95e90

Browse files
committed
Pass outline scenarios to formatters also from the JUnit runner
1 parent 9a86af8 commit 8e95e90

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public List<CucumberExamples> getCucumberExamplesList() {
3838

3939
@Override
4040
public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
41-
format(formatter);
41+
formatOutlineScenario(formatter);
4242
for (CucumberExamples cucumberExamples : cucumberExamplesList) {
4343
cucumberExamples.format(formatter);
4444
List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
@@ -48,6 +48,10 @@ public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
4848
}
4949
}
5050

51+
public void formatOutlineScenario(Formatter formatter) {
52+
format(formatter);
53+
}
54+
5155
CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
5256
// Make sure we replace the tokens in the name of the scenario
5357
String exampleScenarioName = replaceTokens(new HashSet<Integer>(), header.getCells(), example.getCells(), getGherkinModel().getName());

junit/src/main/java/cucumber/runtime/junit/JUnitReporter.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class JUnitReporter implements Reporter, Formatter {
3232
private RunNotifier runNotifier;
3333
EachTestNotifier executionUnitNotifier;
3434
private boolean ignoredStep;
35+
private boolean inScenarioLifeCycle;
3536

3637
public JUnitReporter(Reporter reporter, Formatter formatter, boolean strict) {
3738
this.reporter = reporter;
@@ -186,7 +187,9 @@ public void examples(Examples examples) {
186187

187188
@Override
188189
public void step(Step step) {
189-
steps.add(step);
190+
if (inScenarioLifeCycle) {
191+
steps.add(step);
192+
}
190193
formatter.step(step);
191194
}
192195

@@ -212,11 +215,13 @@ public void close() {
212215

213216
@Override
214217
public void startOfScenarioLifeCycle(Scenario scenario) {
218+
inScenarioLifeCycle = true;
215219
formatter.startOfScenarioLifeCycle(scenario);
216220
}
217221

218222
@Override
219223
public void endOfScenarioLifeCycle(Scenario scenario) {
220224
formatter.endOfScenarioLifeCycle(scenario);
225+
inScenarioLifeCycle = false;
221226
}
222227
}

junit/src/main/java/cucumber/runtime/junit/ScenarioOutlineRunner.java

+9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
import cucumber.runtime.model.CucumberScenarioOutline;
66
import org.junit.runner.Description;
77
import org.junit.runner.Runner;
8+
import org.junit.runner.notification.RunNotifier;
89
import org.junit.runners.Suite;
910
import org.junit.runners.model.InitializationError;
1011

1112
import java.util.ArrayList;
1213

1314
class ScenarioOutlineRunner extends Suite {
1415
private final CucumberScenarioOutline cucumberScenarioOutline;
16+
private final JUnitReporter jUnitReporter;
1517
private Description description;
1618

1719
public ScenarioOutlineRunner(Runtime runtime, CucumberScenarioOutline cucumberScenarioOutline, JUnitReporter jUnitReporter) throws InitializationError {
1820
super(null, new ArrayList<Runner>());
1921
this.cucumberScenarioOutline = cucumberScenarioOutline;
22+
this.jUnitReporter = jUnitReporter;
2023
for (CucumberExamples cucumberExamples : cucumberScenarioOutline.getCucumberExamplesList()) {
2124
getChildren().add(new ExamplesRunner(runtime, cucumberExamples, jUnitReporter));
2225
}
@@ -37,4 +40,10 @@ public Description getDescription() {
3740
}
3841
return description;
3942
}
43+
44+
@Override
45+
public void run(final RunNotifier notifier) {
46+
cucumberScenarioOutline.formatOutlineScenario(jUnitReporter);
47+
super.run(notifier);
48+
}
4049
}

junit/src/test/java/cucumber/runtime/junit/FeatureRunnerTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void should_call_formatter_for_scenario_outline_with_two_examples_table_a
8282
assertEquals("" +
8383
"uri\n" +
8484
"feature\n" +
85+
" scenarioOutline\n" +
86+
" step\n" +
87+
" step\n" +
8588
" examples\n" +
8689
" startOfScenarioLifeCycle\n" +
8790
" background\n" +

junit/src/test/java/cucumber/runtime/junit/JUnitReporterTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public void forward_calls_to_reporter_interface_methods() throws Exception {
216216
jUnitReporter = new JUnitReporter(reporter, mock(Formatter.class), false);
217217

218218
jUnitReporter.startExecutionUnit(executionUnitRunner, mock(RunNotifier.class));
219+
jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
219220
jUnitReporter.before(match, result);
220221
jUnitReporter.step(mockStep());
221222
jUnitReporter.match(match);
@@ -242,6 +243,7 @@ public void creates_step_notifier_with_step_from_execution_unit_runner() throws
242243
jUnitReporter = new JUnitReporter(mock(Reporter.class), mock(Formatter.class), false);
243244

244245
jUnitReporter.startExecutionUnit(executionUnitRunner, notifier);
246+
jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
245247
jUnitReporter.step(mockStep("Step Name"));
246248
jUnitReporter.match(mock(Match.class));
247249
jUnitReporter.result(mockResult());
@@ -256,6 +258,7 @@ public void throws_exception_when_runner_step_name_do_no_match_scenario_step_nam
256258
jUnitReporter = new JUnitReporter(mock(Reporter.class), mock(Formatter.class), false);
257259

258260
jUnitReporter.startExecutionUnit(executionUnitRunner, mock(RunNotifier.class));
261+
jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
259262
jUnitReporter.step(mockStep("Scenario Step Name"));
260263
try {
261264
jUnitReporter.match(mock(Match.class));

0 commit comments

Comments
 (0)