MSTest是否与NUnit的TestCase等效? [英] Does MSTest have an equivalent to NUnit's TestCase?

查看:226
本文介绍了MSTest是否与NUnit的TestCase等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现NUnit中的TestCase功能非常有用,可以快速指定测试参数,而无需为每个测试使用单独的方法. MSTest中有类似的东西吗?

I find the TestCase feature in NUnit quite useful as a quick way to specify test parameters without needing a separate method for each test. Is there anything similar in MSTest?

 [TestFixture]  
 public class StringFormatUtilsTest  
 {  
     [TestCase("tttt", "")]  
     [TestCase("", "")]  
     [TestCase("t3a4b5", "345")]  
     [TestCase("3&5*", "35")]  
     [TestCase("123", "123")]  
     public void StripNonNumeric(string before, string expected)  
     {  
         string actual = FormatUtils.StripNonNumeric(before);  
         Assert.AreEqual(expected, actual);  
     }  
 }  

推荐答案

Microsoft最近宣布了"MSTest V2" (请参阅

Microsoft recently announced "MSTest V2" (see blog-article). This allows you to consistently (desktop, UWP, ...) use the DataRow-attribute!

 [TestClass]  
 public class StringFormatUtilsTest  
 {  
     [DataTestMethod]  
     [DataRow("tttt", "")]  
     [DataRow("", "")]  
     [DataRow("t3a4b5", "345")]  
     [DataRow("3&5*", "35")]  
     [DataRow("123", "123")]  
     public void StripNonNumeric(string before, string expected)  
     {  
         string actual = FormatUtils.StripNonNumeric(before);  
         Assert.AreEqual(expected, actual);  
     }  
 } 

再次,不幸的是,Visual Studio Express的测试资源管理器"无法识别这些测试.但是至少完整"的VS版本现在支持该功能!

Again, Visual Studio Express' Test Explorer unfortunately doesn't recognize these tests. But at least the "full" VS versions now support that feature!

要使用它,只需安装NuGet软件包 MSTest.TestFramework MSTest.TestAdapter (目前均为预发行版本).

To use it, just install the NuGet packages MSTest.TestFramework and MSTest.TestAdapter (both pre-release as of now).

如果不必坚持使用MSTest,而只是使用它来通过Test Explorer运行测试,因为您只有Visual Studio Express版本,则可能是为您提供解决方案:

If don't have to stick with MSTest and you're just using it for being able to run the tests via Test Explorer because you only have a Visual Studio Express edition, then this might be a solution for you:

VsTestAdapter VSIX扩展可以运行NUnit测试通过测试资源管理器.不幸的是,VS Express用户无法安装扩展... 但是幸运的是, VsTestAdapter也附带了一个普通的NuGet-Package

There's the VsTestAdapter VSIX extension for being able to run NUnit tests via Test Explorer. Unfortunately, VS Express users can't install extensions... But fortunately the VsTestAdapter comes with a plain NuGet-Package, too!

因此,如果您是VS Express用户,只需安装VsTestAdapter NuGet-Package并喜欢通过Test Explorer运行NUnit测试/测试用例!

不幸的是,上述陈述是不正确的.尽管完全可以通过Express版本安装该软件包,但它无用,因为它无法利用Test Explorer.以前在TestAdapter的旧版本上有一个旁注,已被删除从 2.0.0的描述页面:

Unfortunately the aforementioned statement isn't true. While it's perfectly possible to install the package via an Express edition, it's useless, since it can't utilize the Test Explorer. There's previously been a side note on an older version of the TestAdapter, which was removed from the 2.0.0's description page:

请注意,它不适用于VS Express

Note that it doesn't work with VS Express

这篇关于MSTest是否与NUnit的TestCase等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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