如何运行与MSTest的多个参数的测试方法? [英] How to run a test method with multiple parameters in MSTest?

查看:917
本文介绍了如何运行与MSTest的多个参数的测试方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NUnit的有一个功能叫做价值观,象下面这样:

  [测试]
公共无效MyTest的(
    [值(1,2,3)INT X,
    [值(A,B)字符串s)
{
    // ...
}

这意味着测试方法将运行6次

  MyTest的(1,A)
MyTest的(1,B)
MyTest的(2,A)
MyTest的(2,B)
MyTest的(3,A)
MyTest的(3,B)

我们正在使用MSTest的现在,没有任何等价物,这样我可以运行多个参数相同的测试?

  [TestMethod的]
公共无效MYTEST()
{
    // ...
}


解决方案

这家饭店目前不支持MSTest的。显然,有一个<一个href=\"http://blogs.msdn.com/b/vstsqualitytools/archive/2009/09/04/extending-the-visual-studio-unit-test-type-part-2.aspx\">extensibility模型,你可以自己实现它。另一种选择是使用<一href=\"http://$c$cclimber.net.nz/archive/2008/01/18/How-to-simulate-RowTest-with-MS-Test.aspx\">data-driven测试的。

我个人的意见是只用NUnit的坚持,虽然...

编辑:由于Visual Studio的2012年,更新1,MSTest的有类似的功能。见@ McAden的 下面回答。

NUnit has a feature called Values, like below:

[Test]
public void MyTest(
    [Values(1,2,3)] int x,
    [Values("A","B")] string s)
{
    // ...
}

This means that the test method will run 6 times:

MyTest(1, "A")
MyTest(1, "B")
MyTest(2, "A")
MyTest(2, "B")
MyTest(3, "A")
MyTest(3, "B")

We're using MSTest now, is there any equivalent for this so that I can run the same test with multiple parameters?

[TestMethod]
public void Mytest()
{
    // ...
}

解决方案

It is unfortunately not supported in MSTest. Apparently there is an extensibility model and you can implement it yourself. Another option would be to use data-driven tests.

My personal opinion would be to just stick with NUnit though...

EDIT: As of Visual Studio 2012, update 1, MSTest has a similar feature. See @McAden's answer below.

这篇关于如何运行与MSTest的多个参数的测试方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆