SpecFlow等同于参数化测试夹具 [英] SpecFlow equivalent to parameterized test fixture

查看:75
本文介绍了SpecFlow等同于参数化测试夹具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SpecFlow编写一组测试,并且希望使用不同的输入数据多次运行每个测试.我可以使用方案大纲来做到这一点,但是我想使用相同的测试用例来运行功能文件中的每个方案.

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.

我知道我可以使用Background共享一个案例的设置,但是我正在寻找Background和Scenario Outline之间的交叉点,我可以在其中为背景提供数据表并运行整个功能每行一次.

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.

在NUnit中,我将使用参数化的测试装置来实现这一目标.在SpecFlow中有什么等效的东西吗?

In NUnit, I’d use a parameterized test fixture to achieve this. Is there any equivalent in SpecFlow?

推荐答案

您可以使用specflow

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; }
}

用法:

    [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 );
          }
     }

您可能必须使用属性或specflow上下文在绑定之间共享数据.运行 Background 时,它将为每个场景创建数据对象,但是跨绑定使用它是用户的责任

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

这篇关于SpecFlow等同于参数化测试夹具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆