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 authored and brasmusson committed May 27, 2017
1 parent 8831fb3 commit a9605e9
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 285 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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.Runtime;
import cucumber.runtime.junit.PickleRunners.PickleRunner;
import cucumber.runtime.model.CucumberFeature;
import gherkin.ast.Feature;
import gherkin.events.PickleEvent;
Expand All @@ -16,8 +20,8 @@
import java.util.ArrayList;
import java.util.List;

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

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

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

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

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

Expand All @@ -78,9 +82,15 @@ private void buildFeatureElementRunners(Runtime runtime, JUnitReporter jUnitRepo
for (PickleEvent pickleEvent : pickleEvents) {
if (runtime.matchesFilters(pickleEvent)) {
try {
ParentRunner pickleRunner;
pickleRunner = new ExecutionUnitRunner(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(pickleRunner);
if(jUnitReporter.stepNotifications()) {
PickleRunner picklePickleRunner;
picklePickleRunner = withStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
} else {
PickleRunner picklePickleRunner;
picklePickleRunner = withNoStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
}
} catch (InitializationError 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class JUnitOptions {

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

/**
* 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-");
} else if (arg.equals("--no-filename-compatible-names") || arg.equals("--filename-compatible-names")) {
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);
}
}
Expand All @@ -50,6 +53,9 @@ boolean allowStartedIgnored() {
boolean filenameCompatibleNames() {
return filenameCompatibleNames;
}
public boolean stepNotifications(){
return stepNotifications;
}

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

0 comments on commit a9605e9

Please sign in to comment.