diff --git a/junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java b/junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java index b3297534eb..9e8d903d7f 100644 --- a/junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java +++ b/junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java @@ -37,7 +37,8 @@ public String getName() { @Override protected Description describeChild(Step step) { - return Description.createSuiteDescription(step.getKeyword() + step.getName() + "(" + getName() + ")"); + int stepNumber = cucumberScenario.getSteps().indexOf(step); + return Description.createSuiteDescription(step.getKeyword() + step.getName() + "(" + getName() + ", Step: " + stepNumber + ")"); } @Override diff --git a/junit/src/test/java/cucumber/junit/ExecutionUnitRunnerTest.java b/junit/src/test/java/cucumber/junit/ExecutionUnitRunnerTest.java new file mode 100644 index 0000000000..131c1bad6b --- /dev/null +++ b/junit/src/test/java/cucumber/junit/ExecutionUnitRunnerTest.java @@ -0,0 +1,41 @@ +package cucumber.junit; + +import static org.junit.Assert.*; + +import gherkin.formatter.model.Step; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; + +import cucumber.io.ClasspathResourceLoader; +import cucumber.runtime.model.CucumberFeature; +import cucumber.runtime.model.CucumberScenario; + +public class ExecutionUnitRunnerTest { + @Test + public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception { + List features = + CucumberFeature.load( + new ClasspathResourceLoader(this.getClass().getClassLoader()), + Arrays.asList(new String[] { "cucumber/junit/feature_with_same_steps_in_scenario.feature" }), + Collections.emptyList()); + + ExecutionUnitRunner runner = + new ExecutionUnitRunner( + null, + (CucumberScenario)features.get(0).getFeatureElements().get(0), + null); + + // fish out the two occurrences of the same step and check whether we really got them + Step stepOccurrence1 = runner.getChildren().get(0); + Step stepOccurrence2 = runner.getChildren().get(2); + assertEquals(stepOccurrence1.getName(), stepOccurrence2.getName()); + + assertFalse("Descriptions must not be equal.", + runner.describeChild(stepOccurrence1) + .equals(runner.describeChild(stepOccurrence2))); + } +} diff --git a/junit/src/test/resources/cucumber/junit/feature_with_same_steps_in_scenario.feature b/junit/src/test/resources/cucumber/junit/feature_with_same_steps_in_scenario.feature new file mode 100644 index 0000000000..2d3a235fa6 --- /dev/null +++ b/junit/src/test/resources/cucumber/junit/feature_with_same_steps_in_scenario.feature @@ -0,0 +1,7 @@ +Feature: Scenario with same step occurring twice + Scenario: + When foo + Then bar + + When foo + Then baz