Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpecFlow - How you properly use the "Background:" command in the feature file?

I've been reading articles, watching some screen-casts and playing around with a few sample/demo tutorials.

I read an article where someone said "don't use too many backgrounds". I was curious so I tried it in SpecFlow's feature file and it highlights as a command.

I've been trying to find some language guide for "Gherkin" since that's what it's written for, but no luck yet.

So how is it used? and is there any documentation that will show me what other commands I'm missing and how to use?

Thanks.

like image 755
Mastro Avatar asked Jan 27 '11 03:01

Mastro


People also ask

How do you put a background in a feature file?

The Background keyword is applied to replicate the same steps before all Scenarios within a Feature File. It should be used for defining simple steps unless we are forced to bring the application to a state which requires complicated steps to be carried out. As requested by the stakeholders of the project.

What is SpecFlow background?

The only special structure you can make in a feature file is the “Background” section. In the background section you can list one or more given steps that will be implicitly included in every scenario of the file. So you can use it to extract common preconditions from the scenarios to avoid duplication.

How many sets of background keyword can be used in a feature file?

There can be only one Background in one Feature file and it allows us to set a precondition for all Scenarios in a Feature file.


1 Answers

I've been trying to find some language guide for "Gherkin" ... but no luck yet.

Since SpecFlow is designed after cucumber (a BDD framework for programming language Ruby) it is a good idea to look into the Cucumber wiki if you have questions about Gherkin.

I found this description of "Background"
https://docs.cucumber.io/gherkin/reference/#background

like image 78
k3b Avatar answered Oct 01 '22 11:10

k3b