Skip to content

Commit f950be5

Browse files
committed
Fixed issue #211. JUnit Descriptions for steps now include the step number within the enclosing scenario, making them unique.
1 parent 353a0fa commit f950be5

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public String getName() {
3737

3838
@Override
3939
protected Description describeChild(Step step) {
40-
return Description.createSuiteDescription(step.getKeyword() + step.getName() + "(" + getName() + ")");
40+
int stepNumber = cucumberScenario.getSteps().indexOf(step);
41+
return Description.createSuiteDescription(step.getKeyword() + step.getName() + "(" + getName() + ", Step: " + stepNumber + ")");
4142
}
4243

4344
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cucumber.junit;
2+
3+
import static org.junit.Assert.*;
4+
5+
import gherkin.formatter.model.Step;
6+
7+
import java.util.Arrays;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
import org.junit.Test;
12+
13+
import cucumber.io.ClasspathResourceLoader;
14+
import cucumber.runtime.model.CucumberFeature;
15+
import cucumber.runtime.model.CucumberScenario;
16+
17+
public class ExecutionUnitRunnerTest {
18+
@Test
19+
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
20+
List<CucumberFeature> features =
21+
CucumberFeature.load(
22+
new ClasspathResourceLoader(this.getClass().getClassLoader()),
23+
Arrays.asList(new String[] { "cucumber/junit/feature_with_same_steps_in_scenario.feature" }),
24+
Collections.emptyList());
25+
26+
ExecutionUnitRunner runner =
27+
new ExecutionUnitRunner(
28+
null,
29+
(CucumberScenario)features.get(0).getFeatureElements().get(0),
30+
null);
31+
32+
// fish out the two occurrences of the same step and check whether we really got them
33+
Step stepOccurrence1 = runner.getChildren().get(0);
34+
Step stepOccurrence2 = runner.getChildren().get(2);
35+
assertEquals(stepOccurrence1.getName(), stepOccurrence2.getName());
36+
37+
assertFalse("Descriptions must not be equal.",
38+
runner.describeChild(stepOccurrence1)
39+
.equals(runner.describeChild(stepOccurrence2)));
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature: Scenario with same step occurring twice
2+
Scenario:
3+
When foo
4+
Then bar
5+
6+
When foo
7+
Then baz

0 commit comments

Comments
 (0)