-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Use deterministic unique ids in Descriptions #1121
Closed
Closed
Changes from all commits
Commits
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 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 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 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
56 changes: 56 additions & 0 deletions
56
junit/src/main/java/cucumber/runtime/junit/IdProvider.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cucumber.runtime.junit; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* JUnit Descriptions require an unique id. However this id should be identical between test | ||
* re-runs. This allows descriptions to be used to determine which failed tests should be rerun. | ||
* | ||
* IdProvider generates predictable unique ids. The feature name is used as a base to disambiguate | ||
* between different features. | ||
*/ | ||
class IdProvider { | ||
|
||
private long id = 0; | ||
private final String base; | ||
|
||
IdProvider(String base) { | ||
this.base = base; | ||
} | ||
|
||
Serializable next() { | ||
return new Id(base, id++); | ||
} | ||
|
||
private static final class Id implements Serializable { | ||
|
||
private final String base; | ||
private final long id; | ||
|
||
private Id(String base, long id) { | ||
this.base = base; | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Id id1 = (Id) o; | ||
return id == id1.id && base.equals(id1.base); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = base.hashCode(); | ||
result = 31 * result + (int) (id ^ (id >>> 32)); | ||
return result; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains 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 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 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
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.
Using a sequence counter as a base for the id-object makes them unpredictable. As I understand it using
and
would result in different ids for the test case from the scenario on line 12 (feature file from the java-calculator example in the repo).
The id should instead be base on the uri(/path) of the feature file and the line number of the feature/scenario/etc.
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.
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.
After reviewing the changes in Gherkin v4 I've changed my opinion. It is indeed much better to use a line based identification.