gpt4 book ai didi

c# - 使用 Visual Studio 2015 Intellitest 进行参数化单元测试

转载 作者:太空狗 更新时间:2023-10-29 20:02:42 24 4
gpt4 key购买 nike

我长期以来一直希望在 MSTest 中看到的一个功能是参数化单元测试 (PUT)。我很高兴听到 Intellitest would be capable of creating said tests .不过,我已经开始使用 Intellitest,我认为我对 PUT 的定义与 Microsoft 的不同。

当我想到“PUT”时,我想到TestCases in NUnit , 或 Theories in xUnit .人们比我聪明得多seem to use the same terminology .

有人能告诉我 Intellitest 是否真的能够以与 NUnit 或 xUnit 相同的方式创建 PUT,或者这是一个重载术语的问题,在 Intellitest 中意味着一件事,而对于大多数其他测试框架来说则是另一回事?谢谢。

最佳答案

As of June 2016 , 此功能已添加到“MSTest V2 ”,可以通过添加 MSTest.TestAdapter 通过 NuGet 安装和 MSTest.TestFramework包:

Install-Package MSTest.TestAdapter
Install-Package MSTest.TestFramework

Be aware that these are different than the version of the test framework that ships with e.g. Visual Studio 2017. To use them, you'll likely need to remove the reference(s) to Microsoft.VisualStudio.QualityTools.UnitTestFramework.

安装这些后,您可以简单地使用 RowDataAttribute,如以下示例所示:

[TestMethod]
[DataRow(1, 1, 2)]
[DataRow(3, 3, 6)]
[DataRow(9, -4, 5)]
public void AdditionTest(int first, int second, int expected) {
var sum = first+second;
Assert.AreEqual<int>(expected, sum);
}

Obviously, you aren't restricted to int here. You can also use string, float, bool, or any other primitive value type.

这与以前可用于 Windows Store App projects 的实现相同,如果您熟悉的话。

关于c# - 使用 Visual Studio 2015 Intellitest 进行参数化单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31731884/

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