我只有一个可以带两个值的参数。我想在测试运行器中看到两组测试,一组用于第一组,一组用于第二组。我怎么能这样做?
答案 0 :(得分:1)
也可以使用[DataSource]属性:
http://callumhibbert.blogspot.com/2009/07/data-driven-tests-with-mstest.html
http://codeclimber.net.nz/archive/2008/01/18/How-to-simulate-RowTest-with-MS-Test.aspx
答案 1 :(得分:0)
MSTest非常有限,但它从未真正困扰过我。您可以像这样进行参数化测试:
[TestMethod] public void SomeMethod_WithValidArgs1_Succeeds()
{
Assert_ThatSomeMethodSucceeds(0, "bla");
}
[TestMethod] public void SomeMethod_WithValidArgs2_Succeeds()
{
Assert_ThatSomeMethodSucceeds(1, "bla");
}
[TestMethod] public void SomeMethod_WithValidArgs3_Succeeds()
{
Assert_ThatSomeMethodSucceeds(1, "funcy");
}
private static void Assert_ThatSomeMethodSucceeds(
int param1, string param2)
{
// Act
SubSystem.SomeMethod(param1, param2);
}