Skip to content

Commit

Permalink
[JUnit] Add --[no-]step-notifications options to JunitOptions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mpkorstanje committed May 27, 2017
1 parent 8831fb3 commit 6beaa7e
Show file tree
Hide file tree
Showing 14 changed files with 691 additions and 287 deletions.
161 changes: 0 additions & 161 deletions junit/src/main/java/cucumber/runtime/junit/ExecutionUnitRunner.java

This file was deleted.

28 changes: 19 additions & 9 deletions junit/src/main/java/cucumber/runtime/junit/FeatureRunner.java
@@ -1,7 +1,11 @@
package cucumber.runtime.junit; package cucumber.runtime.junit;


import static cucumber.runtime.junit.PickleRunners.withNoStepDescriptions;
import static cucumber.runtime.junit.PickleRunners.withStepDescriptions;

import cucumber.runtime.CucumberException; import cucumber.runtime.CucumberException;
import cucumber.runtime.Runtime; import cucumber.runtime.Runtime;
import cucumber.runtime.junit.PickleRunners.PickleRunner;
import cucumber.runtime.model.CucumberFeature; import cucumber.runtime.model.CucumberFeature;
import gherkin.ast.Feature; import gherkin.ast.Feature;
import gherkin.events.PickleEvent; import gherkin.events.PickleEvent;
Expand All @@ -16,8 +20,8 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


public class FeatureRunner extends ParentRunner<ParentRunner> { public class FeatureRunner extends ParentRunner<PickleRunner> {
private final List<ParentRunner> children = new ArrayList<ParentRunner>(); private final List<PickleRunner> children = new ArrayList<PickleRunner>();


private final CucumberFeature cucumberFeature; private final CucumberFeature cucumberFeature;
private Description description; private Description description;
Expand All @@ -38,7 +42,7 @@ public String getName() {
public Description getDescription() { public Description getDescription() {
if (description == null) { if (description == null) {
description = Description.createSuiteDescription(getName(), new FeatureId(cucumberFeature)); description = Description.createSuiteDescription(getName(), new FeatureId(cucumberFeature));
for (ParentRunner child : getChildren()) { for (PickleRunner child : getChildren()) {
description.addChild(describeChild(child)); description.addChild(describeChild(child));
} }
} }
Expand All @@ -50,17 +54,17 @@ public boolean isEmpty() {
} }


@Override @Override
protected List<ParentRunner> getChildren() { protected List<PickleRunner> getChildren() {
return children; return children;
} }


@Override @Override
protected Description describeChild(ParentRunner child) { protected Description describeChild(PickleRunner child) {
return child.getDescription(); return child.getDescription();
} }


@Override @Override
protected void runChild(ParentRunner child, RunNotifier notifier) { protected void runChild(PickleRunner child, RunNotifier notifier) {
child.run(notifier); child.run(notifier);
} }


Expand All @@ -78,9 +82,15 @@ private void buildFeatureElementRunners(Runtime runtime, JUnitReporter jUnitRepo
for (PickleEvent pickleEvent : pickleEvents) { for (PickleEvent pickleEvent : pickleEvents) {
if (runtime.matchesFilters(pickleEvent)) { if (runtime.matchesFilters(pickleEvent)) {
try { try {
ParentRunner pickleRunner; if(jUnitReporter.stepNotifications()) {
pickleRunner = new ExecutionUnitRunner(runtime.getRunner(), pickleEvent, jUnitReporter); PickleRunner picklePickleRunner;
children.add(pickleRunner); picklePickleRunner = withStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
} else {
PickleRunner picklePickleRunner;
picklePickleRunner = withNoStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
}
} catch (InitializationError e) { } catch (InitializationError e) {
throw new CucumberException("Failed to create scenario runner", e); throw new CucumberException("Failed to create scenario runner", e);
} }
Expand Down
8 changes: 7 additions & 1 deletion junit/src/main/java/cucumber/runtime/junit/JUnitOptions.java
Expand Up @@ -14,6 +14,7 @@ public class JUnitOptions {


private boolean allowStartedIgnored = false; private boolean allowStartedIgnored = false;
private boolean filenameCompatibleNames = false; private boolean filenameCompatibleNames = false;
private boolean stepNotifications = true;


/** /**
* Create a new instance from a list of options, for example: * Create a new instance from a list of options, for example:
Expand All @@ -38,7 +39,9 @@ private void parse(List<String> args) {
allowStartedIgnored = !arg.startsWith("--no-"); allowStartedIgnored = !arg.startsWith("--no-");
} else if (arg.equals("--no-filename-compatible-names") || arg.equals("--filename-compatible-names")) { } else if (arg.equals("--no-filename-compatible-names") || arg.equals("--filename-compatible-names")) {
filenameCompatibleNames = !arg.startsWith("--no-"); filenameCompatibleNames = !arg.startsWith("--no-");
} else { } else if (arg.equals("--no-step-notifications") || arg.equals("--step-notifications")) {
stepNotifications = !arg.startsWith("--no-");
} else{
throw new CucumberException("Unknown option: " + arg); throw new CucumberException("Unknown option: " + arg);
} }
} }
Expand All @@ -50,6 +53,9 @@ boolean allowStartedIgnored() {
boolean filenameCompatibleNames() { boolean filenameCompatibleNames() {
return filenameCompatibleNames; return filenameCompatibleNames;
} }
public boolean stepNotifications(){
return stepNotifications;
}


private void printOptions() { private void printOptions() {
loadUsageTextIfNeeded(); loadUsageTextIfNeeded();
Expand Down

0 comments on commit 6beaa7e

Please sign in to comment.