-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Use deterministic unique ids in Descriptions #1134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import cucumber.runtime.RuntimeOptions; | ||
| import cucumber.runtime.io.ClasspathResourceLoader; | ||
| import cucumber.runtime.model.CucumberFeature; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.Description; | ||
| import org.junit.runner.notification.RunNotifier; | ||
|
|
@@ -15,8 +16,11 @@ | |
| import org.mockito.InOrder; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Matchers.argThat; | ||
| import static org.mockito.Mockito.inOrder; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
@@ -89,17 +93,67 @@ public void should_call_formatter_for_scenario_outline_with_two_examples_table_a | |
| } | ||
|
|
||
| private RunNotifier runFeatureWithNotifier(CucumberFeature cucumberFeature) throws InitializationError { | ||
| FeatureRunner runner = createFeatureRunner(cucumberFeature); | ||
| RunNotifier notifier = mock(RunNotifier.class); | ||
| runner.run(notifier); | ||
| return notifier; | ||
| } | ||
|
|
||
| private FeatureRunner createFeatureRunner(CucumberFeature cucumberFeature) throws InitializationError { | ||
| final RuntimeOptions runtimeOptions = new RuntimeOptions("-p null"); | ||
| final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
| final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); | ||
| final RuntimeGlue glue = mock(RuntimeGlue.class); | ||
| final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions, new TimeService.Stub(0l), glue); | ||
| FeatureRunner runner = new FeatureRunner(cucumberFeature, runtime, new JUnitReporter(runtime.getEventBus(), false, new JUnitOptions(Collections.<String>emptyList()))); | ||
| RunNotifier notifier = mock(RunNotifier.class); | ||
| runner.run(notifier); | ||
| return notifier; | ||
| return new FeatureRunner(cucumberFeature, runtime, new JUnitReporter(runtime.getEventBus(), false, new JUnitOptions(Collections.<String>emptyList()))); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void shouldPopulateDescriptionsWithStableUniqueIds() throws Exception { | ||
| CucumberFeature cucumberFeature = TestPickleBuilder.parseFeature("path/test.feature", "" + | ||
| "Feature: feature name\n" + | ||
| " Background:\n" + | ||
| " Given background step\n" + | ||
| " Scenario: A\n" + | ||
| " Then scenario name\n" + | ||
| " Scenario: B\n" + | ||
| " Then scenario name\n" + | ||
| " Scenario Outline: C\n" + | ||
| " Then scenario <name>\n" + | ||
| " Examples:\n" + | ||
| " | name |\n" + | ||
| " | C |\n" + | ||
| " | D |\n" + | ||
| " | E |\n" | ||
|
|
||
| ); | ||
|
|
||
| FeatureRunner runner = createFeatureRunner(cucumberFeature); | ||
| FeatureRunner rerunner = createFeatureRunner(cucumberFeature); | ||
|
|
||
| Set<Description> descriptions = new HashSet<Description>(); | ||
| assertDescriptionIsUnique(runner.getDescription(), descriptions); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a bit unusual for an assert-method to modify its arguments, but checking the uniqueness with a set makes sence - and then the set has been create and can be used subsequently. |
||
| assertDescriptionIsPredictable(runner.getDescription(), descriptions); | ||
| assertDescriptionIsPredictable(rerunner.getDescription(), descriptions); | ||
|
|
||
| } | ||
|
|
||
| private static void assertDescriptionIsUnique(Description description, Set<Description> descriptions) { | ||
| // Note, JUnit uses the the serializable parameter (in this case the step) | ||
| // as the unique id when comparing Descriptions | ||
| assertTrue(descriptions.add(description)); | ||
| for (Description each : description.getChildren()) { | ||
| assertDescriptionIsUnique(each, descriptions); | ||
| } | ||
| } | ||
|
|
||
| private static void assertDescriptionIsPredictable(Description description, Set<Description> descriptions) { | ||
| assertTrue(descriptions.contains(description)); | ||
| for (Description each : description.getChildren()) { | ||
| assertDescriptionIsPredictable(each, descriptions); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class DescriptionMatcher extends ArgumentMatcher<Description> { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most test method uses the non-idomatic form of using underscore, since some/many of us contributors find them easier to read (and in tests readability is even more important than elsewhere), see discussion at #302 (comment)