c# - MSTest 是否有相当于 NUnit 的 TestCase 的工具?

标签 c# nunit mstest testcase rowtest

我发现 NUnit 中的 TestCase 功能非常有用,可以作为指定测试参数的快速方法,而无需为每个测试使用单独的方法。 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”(请参阅 blog-article)。这使您能够一致(桌面、UWP...)使用 DataRow 属性!

 [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 版本现在支持该功能!

要使用它,只需安装 NuGet 包 MSTest.TestFrameworkMSTest.TestAdapter (目前均已预发布)。

旧答案:

如果不必坚持使用 MSTest 并且您只是使用它来通过测试资源管理器运行测试因为您只有 Visual Studio Express 版本,那么这可能是为您提供的解决方案:

这是VsTestAdapter VSIX extension能够通过测试资源管理器运行 NUnit 测试。不幸的是,VS Express 用户无法安装扩展... 但幸运的是VsTestAdapter comes with a plain NuGet-Package ,还有!

因此,如果您是 VS Express 用户,只需安装 VsTestAdapter NuGet-Package 并享受通过测试资源管理器运行 NUnit 测试/测试用例!

<小时/>

不幸的是,上述说法并不正确。虽然完全可以通过 Express 版本安装该软件包,但它没有用,因为它无法使用测试资源管理器。之前有关于older version的旁注。 TestAdapter 的,已从 2.0.0's description page 中删除:

Note that it doesn't work with VS Express

关于c# - MSTest 是否有相当于 NUnit 的 TestCase 的工具?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1010685/

相关文章:

nunit - NUnit 中的 TestActionAttribute 可以在设备自己的 SetUp 方法之前运行 BeforeTest 吗?

unit-testing - 在 Unity3d 测试脚本中,如何从另一个类调用静态函数?

unit-testing - 团队 build : Cannot find generated private accessor

c# - 什么是 yield,在 asp .NET 中使用 yield 有什么好处?

c# - "string"和 "String"有什么区别?

selenium - vstest.console.exe 找不到 nunit 测试

c# - 从 .Net 4.6.1 单元测试引用 .Net 标准项目时缺少方法异常

visual-studio-2010 - Visual Studio 2010 未发现新的单元测试

c# - 计时器和按钮问题

c# - 发送 pdf 声明而不保存在应用程序服务器上