Skip to content

Commit 2ca4488

Browse files
committed
[JUnit] Add --[no-]step-notifications options to JunitOptions
When interacting with cucumber in an IDE it is nice to see the step executions. However presenting step executions to surefire as tests results in strange test counts and weird reports. The --no-step-notifications options ensures steps are not included in descriptions and no events are fired for the execution of steps. Related issues: - #263 - #577
1 parent 19774fc commit 2ca4488

13 files changed

+575
-257
lines changed

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

-161
This file was deleted.

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

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package cucumber.runtime.junit;
22

3+
import static cucumber.runtime.junit.PickleRunners.withNoStepDescriptions;
4+
import static cucumber.runtime.junit.PickleRunners.withStepDescriptions;
5+
36
import cucumber.runtime.CucumberException;
47
import cucumber.runtime.Runtime;
8+
import cucumber.runtime.junit.PickleRunners.PickleRunner;
59
import cucumber.runtime.model.CucumberFeature;
610
import gherkin.ast.Feature;
711
import gherkin.events.PickleEvent;
@@ -16,8 +20,8 @@
1620
import java.util.ArrayList;
1721
import java.util.List;
1822

19-
public class FeatureRunner extends ParentRunner<ParentRunner> {
20-
private final List<ParentRunner> children = new ArrayList<ParentRunner>();
23+
public class FeatureRunner extends ParentRunner<PickleRunner> {
24+
private final List<PickleRunner> children = new ArrayList<PickleRunner>();
2125

2226
private final CucumberFeature cucumberFeature;
2327
private Description description;
@@ -38,7 +42,7 @@ public String getName() {
3842
public Description getDescription() {
3943
if (description == null) {
4044
description = Description.createSuiteDescription(getName(), new FeatureId(cucumberFeature));
41-
for (ParentRunner child : getChildren()) {
45+
for (PickleRunner child : getChildren()) {
4246
description.addChild(describeChild(child));
4347
}
4448
}
@@ -50,17 +54,17 @@ public boolean isEmpty() {
5054
}
5155

5256
@Override
53-
protected List<ParentRunner> getChildren() {
57+
protected List<PickleRunner> getChildren() {
5458
return children;
5559
}
5660

5761
@Override
58-
protected Description describeChild(ParentRunner child) {
62+
protected Description describeChild(PickleRunner child) {
5963
return child.getDescription();
6064
}
6165

6266
@Override
63-
protected void runChild(ParentRunner child, RunNotifier notifier) {
67+
protected void runChild(PickleRunner child, RunNotifier notifier) {
6468
child.run(notifier);
6569
}
6670

@@ -78,9 +82,15 @@ private void buildFeatureElementRunners(Runtime runtime, JUnitReporter jUnitRepo
7882
for (PickleEvent pickleEvent : pickleEvents) {
7983
if (runtime.matchesFilters(pickleEvent)) {
8084
try {
81-
ParentRunner pickleRunner;
82-
pickleRunner = new ExecutionUnitRunner(runtime.getRunner(), pickleEvent, jUnitReporter);
83-
children.add(pickleRunner);
85+
if(jUnitReporter.stepNotifications()) {
86+
PickleRunner picklePickleRunner;
87+
picklePickleRunner = withStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
88+
children.add(picklePickleRunner);
89+
} else {
90+
PickleRunner picklePickleRunner;
91+
picklePickleRunner = withNoStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
92+
children.add(picklePickleRunner);
93+
}
8494
} catch (InitializationError e) {
8595
throw new CucumberException("Failed to create scenario runner", e);
8696
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class JUnitOptions {
1414

1515
private boolean allowStartedIgnored = false;
1616
private boolean filenameCompatibleNames = false;
17+
private boolean stepNotifications = true;
1718

1819
/**
1920
* Create a new instance from a list of options, for example:
@@ -38,7 +39,9 @@ private void parse(List<String> args) {
3839
allowStartedIgnored = !arg.startsWith("--no-");
3940
} else if (arg.equals("--no-filename-compatible-names") || arg.equals("--filename-compatible-names")) {
4041
filenameCompatibleNames = !arg.startsWith("--no-");
41-
} else {
42+
} else if (arg.equals("--no-step-notifications") || arg.equals("--step-notifications")) {
43+
stepNotifications = !arg.startsWith("--no-");
44+
} else{
4245
throw new CucumberException("Unknown option: " + arg);
4346
}
4447
}
@@ -50,6 +53,9 @@ boolean allowStartedIgnored() {
5053
boolean filenameCompatibleNames() {
5154
return filenameCompatibleNames;
5255
}
56+
public boolean stepNotifications(){
57+
return stepNotifications;
58+
}
5359

5460
private void printOptions() {
5561
loadUsageTextIfNeeded();

0 commit comments

Comments
 (0)