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

Controlling Test Execution Order in Serenity BDD (Serenity 4 with JUnit 4) #3610

Open
SrivaniChennupati opened this issue Feb 3, 2025 · 3 comments
Labels

Comments

@SrivaniChennupati
Copy link

@wakaleo : We recently migrated to Serenity 4 with JUnit 4, and we are looking for ways to control the order of execution of our test scenarios. Currently, our tests run in an unpredictable order, and we need a way to define a specific sequence.

Could you please confirm if there’s a built-in way to control execution order in Serenity BDD?

@wakaleo
Copy link
Member

wakaleo commented Feb 3, 2025

This is not possible by design in JUnit (relying on test execution order can mean you have dependencies between your tests), but in JUnit 5 you can use the Order annotation for that.

@SrivaniChennupati
Copy link
Author

SrivaniChennupati commented Feb 5, 2025

@wakaleo Since we can define the @order annotation at the method level , which applies to test methods, will that help us control the execution order of scenarios in serenity BDD feature files ?

I upgraded JUnit from version 4 to 5 in our Serenity BDD pom.xml. Now, the @order annotation can be defined at the step definition class level. I was wondering if this can control the execution order of feature files or scenarios in my feature files.

@wakaleo
Copy link
Member

wakaleo commented Feb 5, 2025

No, the order annotation is a JUnit 5 annotation. BDD scenarios are executed in order of appearance in the feature file, unless you run them in parallel (in which case the order is not determined).

There are a few hacks you can do to control the order of execution of the feature files themselves, byt wanting to do so is usually a red flag that your scenarios or features have dependencies, which leads to brittle test suites.

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

No branches or pull requests

2 participants