gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:50:32 25 4
gpt4 key购买 nike

我发现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com