【发布时间】:2015-01-26 13:38:36
【问题描述】:
我正在尝试使用 NUnit 框架运行一些性能测试,例如:
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
[TestCase(1000)]
public void SaveBookingTest(int numberOfItems)
{
var stopwatch = new Stopwatch();
var items = DataFactory.CreateItems(numberOfItems);
stopwatch.Start();
service.SaveItems(items);
stopwatch.Stop();
SaveResults(stopwatch.ElapsedMilliseconds);
}
... 结果是:
- 22:56:01:在数据库中保存 1000 个项目:48353 毫秒 - 平均:20,6812400321 个项目/秒。
- 22:56:02:在数据库中保存 1 项:40 毫秒 - 平均:25 项/秒。
- 22:56:06:在数据库中保存 100 个项目:3813 毫秒 - 平均:26,2260687323 个项目/秒。
- 22:56:07:在数据库中保存 10 项:413 毫秒 - 平均:24,2130750605 项/秒。
所以我期望[TestCase(1)] 将首先运行,然后[TestCase(10)] 等等。但正如您从结果中看到的那样,这不会发生。有没有办法控制这个?哪个测试用例首先完成似乎是随机的。
根据NUnit documentation,我猜答案是你不能。
因此,当 TestCaseAttribute 在一个方法上多次出现或当其他提供数据的属性与 TestCaseAttribute 结合使用时,测试用例的顺序是不确定的。
你们有什么好的想法来控制执行吗?小技巧? 另一种方法?有什么事吗?
【问题讨论】:
标签: c# .net nunit testcase order-of-execution