问题
I’m using SpecFlow to write a set of tests, and I’d like to run each test multiple times, with different input data. I could do this with scenario outlines, but I want to run every scenario in the feature file with the same test cases.
I know I can use the Background to share the setup for one case, but I’m looking for something like a cross between Background and Scenario Outline, where I can supply a table of data to the Background and run the entire feature file once per row.
In NUnit, I’d use a parameterized test fixture to achieve this. Is there any equivalent in SpecFlow?
回答1:
You can utilize specflow assist helpers to create data table object and use it in Background
Background:
Given I’ve Entered The Following Information
| FirstName| LastName|Email |
| Abcd1 | Xyz1 |abc1@xyz1.com|
| Abcd2 | Xyz2 |abc2@xyz2.com|
class Person
{
string FirstName { get; set; }
string LastName { get; set; }
string email { get; set; }
}
Usage:
[Binding]
[Given(@"I’ve Entered The Following Information")]
public void UseData(TechTalk.SpecFlow.Table table)
{
var enumeratePersons = table.CreateSet<Person>();
foreach (Person P in enumeratePersons ){
log.Info(P.FirstName + " " + P.LastName );
}
}
You might have to use properties or specflow context to share data between bindings. When Background
is run , it will create the data object for each scenario but to use it across bindings is user's responsibility
来源:https://stackoverflow.com/questions/59146845/specflow-equivalent-to-parameterized-test-fixture