【问题标题】:Parameterized Unit Tests with Visual Studio 2015 Intellitest使用 Visual Studio 2015 Intellitetest 进行参数化单元测试
【发布时间】:2015-10-22 06:56:56
【问题描述】:

我一直想在 MSTest 中看到的一个功能是参数化单元测试 (PUT)。我很高兴听到 Intellitet would be capable of creating said tests。但是,我已经开始使用 Intellitetest,并且我认为我对 PUT 的定义与 Microsoft 的不同。

当我想到“PUT”时,我会想到 TestCases in NUnitTheories in xUnit。比我聪明得多的人seem to use the same terminology

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

【问题讨论】:

    标签: c# unit-testing visual-studio-2015 parameterized-unit-test intellitest


    【解决方案1】:

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

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

    请注意,这些版本与随附的测试框架版本不同,例如Visual Studio 2017。要使用它们,您可能需要删除对 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);
    }
    

    显然,您在此处不限于int。您也可以使用stringfloatbool 或任何其他primitive value type

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

    【讨论】:

      【解决方案2】:

      Intellitetest 生成的参数化单元测试与其他测试框架中常见的 PUT不同

      在 MSTest/Intellitet 世界中,PUT 用于intelligently generate other unit tests

      为了在 MSTest 中使用不同的数据集多次执行测试,我们仍然需要与Data-Driven Unit Tests 搏斗,或者按照How to RowTest with MSTest? 中的建议使用MSTestHacks

      【讨论】:

        【解决方案3】:

        参数化单元测试 (PUT) 是通过使用参数对单元测试的直接概括。 PUT 对整个可能的输入值集的代码行为进行陈述,而不仅仅是单个示例性输入值。在这个程度上,它类似于您提供的链接。不同之处在于生成数据以输入参数化单元测试 - IntelliTest 可以自动为 PUT 生成输入数据。我请求您参考以下内容: http://blogs.msdn.com/b/visualstudioalm/archive/2015/07/05/intellitest-one-test-to-rule-them-all.aspx 用于上下文。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-08-13
          • 2016-11-13
          • 2017-11-03
          • 2012-07-24
          • 1970-01-01
          • 1970-01-01
          • 2016-07-27
          • 1970-01-01
          相关资源
          最近更新 更多