unit-testing - SpecFlow equivalent to parameterized test fixture
问题描述
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?
解决方案
您可以利用 specflow辅助助手创建数据表对象并将其用于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 );
}
}
您可能必须使用属性或规范流上下文在绑定之间共享数据。运行时Background
,它将为每个场景创建数据对象,但跨绑定使用它是用户的责任
推荐阅读
- javascript - ReactNative:无法从 NativeModules 调用函数
- node.js - MEAN Stack:当 Angular 在 Node 文件夹中时,如何从 Node 启动 Angular
- javascript - 如何更改画布文本的字体大小
- rest-assured-jsonpath - RestAssured - JsonPath 表达式过滤器不起作用
- python - 如何按主题列出多个主题的订阅?
- c# - 使用 c# 从 Sqlite 表中获取特定客户的值的总和
- php - 如何使用codeigniter将url作为参数从视图传递到控制器
- java - 创建一个带有 X 的星号框
- r - 如何使用 R 中的嵌套 ifelse() 对数据进行编码
- html - 当空间可用时,背景图像会拉伸