Skip to content

Commit

Permalink
Added Petter Måhlén's JUnit 4.11 changes. Closes #322, #445.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jan 12, 2013
2 parents 842ecca + 16cb45d commit 435d9bd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.1.1...master)

* [JUnit] Upgrade to 4.11 (Aslak Hellesøy)
* [JUnit] Upgrade to 4.11 ([#322](https://github.com/cucumber/cucumber-jvm/issues/322) [#445](https://github.com/cucumber/cucumber-jvm/pull/445) Petter Måhlén, Aslak Hellesøy)
* [Spring] Upgrade to 3.2.0.RELEASE (Aslak Hellesøy)
* [Core] Strip command line arguments in case people accidentally invoke `cucumber.api.cli.Main` with arguments that have spaces left and right. (Aslak Hellesøy)
* [Core] Implemented `DataTable.equals()` and `DataTable.hashCode()`. (Aslak Hellesøy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gherkin.formatter.model.BasicStatement;
import gherkin.formatter.model.Step;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Description getDescription() {
protected Description describeChild(Step step) {
Description description = stepDescriptions.get(step);
if (description == null) {
description = Description.createSuiteDescription(step.getKeyword() + step.getName(), step);
description = Description.createTestDescription(getName(), step.getKeyword() + step.getName(), step);
stepDescriptions.put(step, description);
}
return description;
Expand Down
4 changes: 2 additions & 2 deletions junit/src/test/java/cucumber/runtime/junit/CucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public void ensureOriginalDirectory() {
@Test
public void finds_features_based_on_implicit_package() throws IOException, InitializationError {
Cucumber cucumber = new Cucumber(ImplicitFeaturePath.class);
assertEquals(2, cucumber.getChildren().size());
assertEquals(3, cucumber.getChildren().size());
assertEquals("Feature: FA", cucumber.getChildren().get(0).getName());
}

@Test
public void finds_features_based_on_explicit_root_package() throws IOException, InitializationError {
Cucumber cucumber = new Cucumber(ExplicitFeaturePath.class);
assertEquals(2, cucumber.getChildren().size());
assertEquals(3, cucumber.getChildren().size());
assertEquals("Feature: FA", cucumber.getChildren().get(0).getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cucumber.runtime.model.CucumberScenario;
import gherkin.formatter.model.Step;
import org.junit.Test;
import org.junit.runner.Description;

import java.util.Collections;
import java.util.List;
Expand All @@ -17,22 +18,53 @@ public class ExecutionUnitRunnerTest {
@Test
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
List<CucumberFeature> features = CucumberFeature.load(
new ClasspathResourceLoader(this.getClass().getClassLoader()),
asList("cucumber/runtime/junit/fb.feature"),
Collections.emptyList()
new ClasspathResourceLoader(this.getClass().getClassLoader()),
asList("cucumber/runtime/junit/fb.feature"),
Collections.emptyList()
);

ExecutionUnitRunner runner = new ExecutionUnitRunner(
null,
(CucumberScenario) features.get(0).getFeatureElements().get(0),
null
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)));
// then check that the descriptions are unequal
Description runnerDescription = runner.getDescription();

Description stepDescription1 = runnerDescription.getChildren().get(0);
Description stepDescription2 = runnerDescription.getChildren().get(2);

assertFalse("Descriptions must not be equal.", stepDescription1.equals(stepDescription2));
}

@Test
public void shouldIncludeScenarioNameAsClassNameInStepDescriptions()
throws Exception {

List<CucumberFeature> features = CucumberFeature.load(
new ClasspathResourceLoader(this.getClass().getClassLoader()),
asList("cucumber/runtime/junit/feature_with_same_steps_in_different_scenarios.feature"),
Collections.emptyList()
);

ExecutionUnitRunner runner = new ExecutionUnitRunner(
null,
(CucumberScenario) features.get(0).getFeatureElements().get(0),
null
);

// fish out the data from runner
Step step = runner.getChildren().get(0);
Description runnerDescription = runner.getDescription();
Description stepDescription = runnerDescription.getChildren().get(0);

assertEquals("description includes scenario name as class name", runner.getName(), stepDescription.getClassName());
assertEquals("description includes step keyword and name as method name", step.getKeyword() + step.getName(), stepDescription.getMethodName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: In cucumber.junit
Scenario: first
When step
Then another step

Scenario: second
When step
Then another step

0 comments on commit 435d9bd

Please sign in to comment.