Skip to content
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

Enable Random order in cucumber engine #2849

Open
Blackwolf291 opened this issue Feb 20, 2024 · 2 comments
Open

Enable Random order in cucumber engine #2849

Blackwolf291 opened this issue Feb 20, 2024 · 2 comments

Comments

@Blackwolf291
Copy link

Blackwolf291 commented Feb 20, 2024

🤔 What's the problem you're trying to solve?

I'm a team lead on a team currently implementing cucumber, and one of our usecases is being able to run individual features and scenarios. This is well supported, but to ensure this will work for any items, the features should be ran in a random (probably seeded) order, to highlight scenario dependencies. This is available in most versions of cucumber across languages, as well as in the cucumber core for java, but there is no way to access it in cucumber engine.

✨ What's your proposed solution?

Based on the existing property names and namespace for cucumber engine, and this feature in other environments that have it, introduce property cucumber.execution.order into cucumber engine. Cucumber engine already forwards all properties starting with "cucumber." from all sources so getting it should be smooth. From there its value should be mapped onto the correct PickleOrder value. Default should preserve existing behavior (lexical). Other options are random, random(seeded) and reverse lexical. I need random at least, but random(seeded) would be better.

⛏ Have you considered any alternatives or workarounds?

It's not usually recommended to hack into 3rd party libraries from your testcode, which leaves only hightened manual vigilance as an option.

📚 Any additional context?

Would be happy to try implementing it myself if your team will have the PR.


This text was originally generated from a template, then edited by hand. You can modify the template here.

@mpkorstanje
Copy link
Contributor

I would be happy to accept a pull request for this!

You can add a step to the DiscoverySelectorResolver that randomizes the features.

void resolveSelectors(EngineDiscoveryRequest request, CucumberEngineDescriptor engineDescriptor) {
Predicate<String> packageFilter = buildPackageFilter(request);
resolve(request, engineDescriptor, packageFilter);
filter(engineDescriptor, packageFilter);
pruneTree(engineDescriptor);
}

To randomize the pickles, be aware that the JUnit Platform represents tests in a tree. For implementation hints, please have a look at JUnit Jupiter:

https://github.com/junit-team/junit5/blob/d4adab8e08e9c73ecbfdef21638cfe3022c61fe5/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/DiscoverySelectorResolver.java#L41C1-L42

And specifically the comments at:

https://github.com/junit-team/junit5/blob/d4adab8e08e9c73ecbfdef21638cfe3022c61fe5/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/AbstractOrderingVisitor.java#L99-L101

Note that currently we don't use the EngineDiscoveryRequestResolver but will after #2835 is done. This may require us to resolve some merge conflicts, but I don't think they'll be significant.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Feb 20, 2024

And pulling #2835 back into memory I see that I already had to implement some ordering and stalled there. So you may want to consider building on that PR instead. But I would accept either one of these solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants