微软最近宣布“MS测试V2” (see 博客文章)。这使您能够一致(桌面、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.测试框架 and MSTest.TestAdapter(目前均已预发布)。
较旧的答案:
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, too!
So, if you're a VS Express user, just install the VsTestAdapter NuGet-Package and enjoy running your NUnit tests/testcases via Test Explorer!
不幸的是,上述说法并不正确。虽然完全可以通过 Express 版本安装该软件包,但它没有用,因为它无法使用测试资源管理器。之前有一个旁注旧版本TestAdapter 的,已从2.0.0的描述页面:
请注意,它不适用于 VS Express