Skip to main content
 首页 » 编程设计

c#之MSTest 相当于 NUnit 的参数化测试吗

2024年05月29日19yjmyzz

NUnit 支持一项功能,您可以为要多次运行的单元测试指定一组数据输入。

[RowTest] 
[Row(1001,1,2,3)] 
[Row(1,1001,2,3)] 
[Row(1,2,1001,3)] 
public void SumTests(int x, int y, int z, int expected) 
{ 
   ... 
} 

使用 MSTest 完成此类任务的最佳方法是什么?我找不到类似的属性集。

请您参考如下方法:

对于那些使用 MSTest2 的用户,DataRow + DataTestMethod 可以准确地执行此操作:

[DataRow(Enum.Item1, "Name1", 123)] 
[DataRow(Enum.Item2, "Name2", 123)] 
[DataRow(Enum.Item3, "Name3", 456)] 
[DataTestMethod] 
public void FooTest(EnumType item, string name, string number) 
{ 
    var response = ExecuteYourCode(item, name, number); 
 
    Assert.AreEqual(item, response.item); 
} 

更多关于 here