我正在编写一个测试,我想重用它,因此我试图对整个表进行参数化。该表位于我的“然后”声明中,需要验证的表取决于团队。
目前我的场景大纲如下所示:
Given <teamName> uses this end point
And the response is a Json
When I perform a query to http:...
Then I validate all the fields I need:
|DataElement|Validation |jsonPath |
|element1 |validate that it is not null |data.structure.path|
|element2 |validate a name |data.structure.name|
所以我知道我可以通过参数化表中的数据来验证每一行:
|DataElement|Validation |jsonPath |
|<value> |<Specific validation performed>|<Json Path to query|
然后做例子
但是根据哪个团队使用相同的端点,所需的数据元素和验证非常不同,所以我想参数化整个表对象,如下所示:
然后我验证我需要的所有字段:
<TeamTable>
Examples:
|Team A Table|
|DataElement|Validation |jsonPath |
|element1 |validate that it is not null |data.structure.path|
|element2 |validate a name |data.structure.name|
|element1 |validate age is valid |data.structure.age |
|Team B Table|
|DataElement|Validation |jsonPath |
|element1 |validate is a Date |data.structure.date |
|element2 |validate something more |data.structure.something|
|element1 |validate US postcode |data.structure.postcode |
是否可以?如何参数化整个表?
最佳答案
Specflow 确实支持表参数,这里是一个例子:
When following transactions are added
| TransactionDate | TransactionAmount | AccountNumber | Type | CR/DR |
| 1/20/12 | 10,000 | 102 | Cash | DR |
| 1/20/12 | 6,500 | 106 | Cash | DR |
| 1/21/12 | 10,001 | 102 | Cash | DR |
[When(@"following transactions are added")]
public void WhenFollowingTransactionsAreAdded(Table table)
{
// Now you can either do for each
foreach (var row in table.Rows)
{
// do stuf
}
// Or use an assist helpers to map table to an object
var transactions = table.CreateSet<Transaction>();
}
有关 Assist 助手的更多帮助,请参阅 SpecFlow docs
更多关于表格的基本信息 here
关于Specflow 参数化整表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11949669/