Question

I have a feature file with some tags:

MyFeature.feature:

...
@RestoreDB
@SomeAction
Scenario outline: ...
...

and binding cs file:

MySteps.cs:

[Binding]
public class MySteps:
{
   [BeforeScenario("RestoreDB")]
   public void RestoreDB() { ... }

   [BeforeScenario("SomeAction")]
   public void SomeAction() { ... }
}

SpecFlow executes BeforeScenario in an unordered sequence.

Is it possible to set ordering of execution RestoreDB tag always before SomeAction tag??

Était-ce utile?

La solution

It is not possible to specify the order in which BeforeScenario hooks are executed. You can see a discussion of this issue on the SpecFlow github site here.

I can understand why you may use BeforeScenario to execute a "RestoreDB" method (e.g. to set up the system for the test), however I'd be wary about restoring "system state" which you mention in your comment; what exactly is this "system state"? If this "system state" is not related to your DB data, then I'd question why you'd put this in the BeforeScenario.

A SpecFlow scenario should execute a feature in it's entirety. Instead of setting up system state in the BeforeScenario you should include the steps as part of the scenario instead. If that step is used in many places you could use a SpecFlow Background to achieve this, as opposed to using a BeforeScenario hook.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top