SpecFlow equivalent to parameterized test fixture

断了今生、忘了曾经 提交于 2021-01-28 10:21:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!