I have had my feature file in Cucumber and am using Given, When, Then syntax(Gherkin) to write my scenarios in it and have the corresponding steps in the Step Definition file. I have a scenario, where I am checking if a particular data set exists(which is part of my Given step ) then continue with my next steps for "Then", "And" etc But if it's not, then it should skip rest of the steps and exit out of the Step Definition file without failing the scenario. Can someone please advise if this is supported in Cucumber? If yes, what is the best way to do it?
You can use JUnits Assume
or TestNG's SkipException
to mark a test as skipped if a specific assumption fails. Skipped tests are not considered failures.
From https://github.com/cucumber/cucumber-jvm/tree/master/junit
Through Assume JUnit provides:
a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information. The default JUnit runner skips tests with failing assumptions. Custom runners may behave differently.
The Cucumber runner supports Assume and will marked skipped scenarios as skipped.
From https://github.com/cucumber/cucumber-jvm/tree/master/testng
Cucumber provides limited support for SkipException.
- Throwing a SkipException results in both Cucumber and TestNG marking the test as skipped.
- Throwing a subclass of SkipException results in Cucumber marking the test as failed and TestNG marking the test as skipped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With