【问题标题】:Live Testing not working with NUnit实时测试不适用于 NUnit
【发布时间】:2018-08-28 01:36:36
【问题描述】:

当我打开实时测试时,我的测试显示“已从实时单元测试中排除”。这只发生在我使用 NUnit 时,使用 MSTest 可以正常工作。

我有: Visual Studio 企业版 2017 (15.6.2) NUnit 3.10.1

简单的代码示例

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }
    }

    [TestFixture]
    public class NUnitTest1
    {
        [Test]
        public void NUnitTestMethod1()
        {
        }
    }
}

TestMethod1() 在烧杯旁边有一个绿色复选标记,表示 Live Unit 测试已开启并被测试覆盖。 NUnitTestMethod1() 有烧杯,但没有复选标记,鼠标悬停在上面会显示“已从实时单元测试中排除”。

我错过了什么?除了我通过 Nuget 添加 NUnit 并添加额外的测试类/方法之外,没有进行其他编辑或更改。我正在全新安装的 Visual Studio 上运行,其中唯一添加的其他内容是 ReSharper Ultimate (2017.3.2)。

【问题讨论】:

    标签: visual-studio unit-testing nunit


    【解决方案1】:

    您不能在一个项目中混合使用两个测试框架。 Visual Studio 检查每个已安装的测试适配器以查看它是否处理给定的测试项目。一旦找到一个有效的,它就会停止检查其他的。在您的情况下,将使用 MSTest 适配器,并且由于 MSTest 适配器不理解 NUnit 测试,因此它不会运行这些测试。

    创建一个单独的 NUnit 测试项目,确保您不引用 MSTest 并将 NUnit 3.10.0 和 NUnit3TestAdapter 3.10 NuGet 包添加到您的项目中。如果您使用的是 .NET 4.x,那应该可以让您启动并运行。如果您的目标是 .NET Core,请参阅 NUnit 文档了解更多信息,https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

    这是 15.6.2 中 NUnit 项目的实时单元测试。注意绿色复选标记。

    【讨论】:

    • 在 Visual Studio 2017 Enterprise 15.7.5 和 VS 2017 15.8 Preview 3 上,NUnit 无法按预期使用 LUT,TestCaseAttribute 使 LUT 出现一些错误。 An exception occurred while invoking executor 'executor://nunit3testexecutor/': Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.
    • @gdyrrahitis 我现在也明白了。往往会工作一次,然后如果我进行任何更改它会停止测试,直到我清除 LUT。
    • @gilliduck 我发现的唯一解决方法是:1) 下载 Visual Studio 2017 Preview 15.8,并在我的测试项目中包含这个包:Microsoft.TestPlatform.TestHost。还要确保输出类型为 exe,<OutputType>Exe</OutputType>。这行得通。
    【解决方案2】:

    你有 NUnit 和 NUnit3TestAdapter 吗?根据docs,您需要 NUnit 3.5.0 和 NUnit3TestAdapter 3.5.1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多