Is it valid to have specflow features depending on other features?

后端 未结 2 2034
春和景丽
春和景丽 2021-01-24 03:21

I want to write an acceptance test along the lines of

given the first test has run
when I do this new test
then this new test passes

This is be

2条回答
  •  醉梦人生
    2021-01-24 03:49

    yes you can do this in specflow, but with a slight caveat. this approach will not run one scenario, then run the other, it will run the first scenario on its own, then the dependent scenario will run the first scenario again followed by the second scenario. The order of these may not be deterministic. We have avoided this issue by @ignore the first scenario once the dependent scenario is written. As the second scenario always runs the first scenario anyway it doesn't matter that its @ignored, as any failure in the first scenario will trigger a failure in the second scenario.

    What we have done to achieve this is along these lines:

    Scenario: Some base scenario
        Given some condition
        When some action
        Then some result
    

    then later in another feature:

    Scenario: Some dependant scenario
        Given some base scenario has happened
        And some other condition
        When some other action
        Then some other result
    

    The key is in the definition of the step Given some base scenario has happened

    if you define this step like this:

    [Given("some base scenario has happened")]
    public void SomeBaseScenarioHasHappened()
    {
        Given("some condition");
        When("some action");
        Then("some result");
    }
    

    you need to ensure that your class which holds your step definitions derives from the base Steps class in specflow to get access to the Given, When and Then methods:

    [Binding]
    public class MyStepClass: Steps
    

    you can find more information on this on the specflow wiki

提交回复
热议问题