开发者

Specflow: Can some step definitions be used feature wide?

When a feature requires some given steps, you need to specify for each scenario "Given I have done something And something else And the last thing...". Doing all those steps for every scenario can be tedious.

One solution could be to specify all this in one Given step (Given I am set up to test feature X). However, it's not something very precise while reading the feature steps.

This is why I'd like to know if step definitions can be used feature wide. I'd use something like this :

Feature: My feature

Obvi开发者_StackOverflowous feature description here.

Given I have done something
And something else
And the last thing

Scenario: Y validation

When I type X
Then I should see Y

Scenario: Z validation

When I type X
Then I should see Z

Over this :

Feature: My feature

Obvious feature description here.

Scenario: Y validation

Given I have done something
And something else
And the last thing
When I type X
Then I should see Y

Scenario: Z validation

Given I have done something
And something else
And the last thing
When I type X
Then I should see Z

Any solution is welcome, but I'd like something that can be understood while reading the .feature file, instead of having to dig in the code.

Thanks


There a great and easy solution to your problem in Gherkin, the language used to write feature files. It's called Background and is a couple of steps that is executed before each scenario in the file.

See this wiki page for more information; https://github.com/cucumber/cucumber/wiki/Background


When using the Backgroung tag your scenarios and feature will look more or less like this:

Feature: My feature
     As a person
     I want to do something
     So that something can happen

Background: My Background
Given I have done something
And something else
And the last thing

Scenario: Y validation
      When I type X
      Then I should see Y

Scenario: Z validation
      When I type X
      Then I should see Z
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜