You cannot dynamically skip test scenarios using the oft suggested raising an AssumptionViolatedException
or using Assume.assumeTrue(false)
. This still results in a failed build, exiting with code 1, which makes it unfit for use in a CI/CD pipeline.
What does work however, is using Assumptions.assumeTrue(false);
Source. For example:
@Before
public void before(Scenario scenario) {
Assumptions.assumeFalse(
scenario.getSourceTagNames().contains("@skipme")
);}
Additional remarks:
- Figuring this out took me way too much time. Maybe if I searched for ‘abort test’ instead of ‘conditionally skip scenario’, I would’ve figured it out sooner.
- When implementing a
Before("@sometag")
and@Before
function, both will be run for a scenario marked with ‘@sometag’. - Using the exception/Assume can work with a different runner: when running the scenario using JetBrain’s IntelliJ IDEA, the scenario will be nicely marked as ‘skipped’.
Of course, you can achieve the same by using tag filtering in your runner. The dynamic approach enables using your existing test set in a more flexible way. You can filter scenario execution based on product versions, web browser used and other (environment) parameters. All without having to keep or maintain multiple specific purpose run configurations.