【发布时间】:2018-01-30 11:12:08
【问题描述】:
在 Specflow 中,虽然我知道 Scenario Outline / Examples 功能,但我想知道是否有更优雅的方法来生成要在测试用例中使用的范围和组合?
例如,在 vanilla NUnit 中,我可以使用 TestCaseSource 或 Theory 构建生成器,我可以将大量测试用例输入到测试中。
private static readonly IEnumerable<int> Numbers = Enumerable.Range(1, 50);
[TestCaseSource(nameof(Numbers))]
public void TestFoo(int number)
{
// Test goes here.
}
目前,在我的测试中,我需要在 Examples 中手动创建所有排列,这可能难以阅读,并且可能容易出错。
Scenario Outline: Count things
Given I'm playing a game of counting
When I count to <number>
Then the highest number I should have counted to should be <number>
Examples:
| number|
| 1 |
| 2 |
| 3 |
...
| 50 |
我真正想做的是
Examples:
| number| : Range 1 to 20
更好的是,创建两组的笛卡尔积,即:
Examples:
| number1| : Range 1 to 20
| number2| : Range 5 to 10
// i.e. 20 x 5 = 100 combinations of the tuple (number1, number2)
我是否可以在 Specflow 中更优雅地处理这个问题?
【问题讨论】:
-
您尝试过同时使用CombinatorialAttribute 和ValueSourceAttribute 吗?
-
道歉 - 我不应该标记 NUnit - 但你是对的,我正在尝试从 SpecFlow(即 Cucumber 语言)中寻找是否有等效的方式来利用自动化数据底层测试框架的驱动功能(如 NUnit 的 Theory、Combinatorial、TestCaseSource(带有生成的数据集)。我已经更新了标签。