2011-03-31 111 views
2

我只有一个参数可以取两个值。我想在测试跑步者中看到两套我的测试,一种是第一种,一种是第二种。我怎样才能做到这一点?有没有办法使用MSTest来运行一组参数的所有测试?

+1

你应该看看Pex的HTTP://weblogs.asp。 net/robertxue/archive/2008/11/10/using-the-pex-to-write-unit-test-automatically.aspx – 2011-03-31 19:34:18

回答

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); 
} 
相关问题