Question

For me to execute something at the TestRun, Feature, Scenario or Step level.. I understand we can use Hooks. What i would like to find out is how these can be writte in the feature file when I am writting the spec.

Based on my understanding I can use Backgroud to write something common which is to be run within the feature before all the scenarios. However its adviced that we should not have long list in the Backgroud section. Also if I have something which is common for the testrun or multiple feature where i can use a tag a group them, is there any syntax I can use to write this.

Was it helpful?

Solution

The hook implementations cannot be expressed in Gherkin in the feature files, they must be implemented in the step implementation files:

Tag the scenarios and/or features with a tag @foo, and in some class decorated with the [Binding] attribute, annotate a method with a hook attribute, like [BeforeTestRun("foo")].

More information and available hooks can be found in the specflow wiki.

If you're worried about having a long list of steps in the Background, maybe the steps are too verbose and you can consider joining them into a single step. If you need to do something for all tests in the test run, maybe it's not important to mention it in the feature anyways, so it can go in a step implementation file like described above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top