我们如何在 MSTest 中运行具有多个参数的测试方法? [英] How can we run a test method with multiple parameters in MSTest?

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

问题描述

NUnit 有一个名为 Values 的功能,如下所示:

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 six times:

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

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

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

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

推荐答案

很遗憾,旧版本的 MSTest 不支持它.显然有一个 可扩展性模型,您可以自己实现.另一种选择是使用 数据驱动的测试.

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

我个人的意见是坚持使用 NUnit...

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

从 Visual Studio 2012 更新 1 开始,MSTest 具有类似的功能.请参阅麦卡登的回答.

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

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

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