我有测试功能:
[TestMethod()]
public void CreateTest(string input)
{
string expected = "321";
Assert.AreEqual(expected, input);
}
我需要用不同的数据运行这个测试:CreateTest("321");创建测试(“123”);创建测试(空);
在我执行类似 [TestCase("123")], [TestCase("321")]
我需要这样的东西:
[RowTest]
[Row(1,1,2)]
[Row(2,1,3)]
[Row(1,-1,0)]
public void SumTest(int a1, int a2, int result)
{
Assert.AreEqual(a1 + a2, result);
}
最佳答案
你试过了吗data-driven unit testing ?它不使用类属性,但它应该为您提供相同的结果。
如果您想实现高代码覆盖率,请采取 look at the Pex power tool .
如果您想为您的测试建模 ( MBT ),Spec Explorer is also worth review .
关于c# - 测试具有不同值的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10702780/