【问题标题】:Tests not showing in TestExplorer using Asp.Net core and Nunit使用 Asp.Net 核心和 Nunit 在 TestExplorer 中未显示的测试
【发布时间】:2016-08-10 13:14:23
【问题描述】:

请注意,我对 C# 和测试还很陌生。

我的测试没有显示在测试资源管理器中。我正在使用 Visual Studio 2015 更新 3 以及使用新的 asp.net 核心项目结构。

我的 project.json 文件如下所示:

{
  "version": "1.0.0-*",
  "description": "Tests for the earthworm",

  "dependencies": {
    "earthworm": "1.0.0-*",
    "NSubstitute": "2.0.0-rc",
    "NUnit.Runners": "3.4.1",
    "NUnit3TestAdapter": "3.4.1",
    "NUnitLite": "3.4.1",
    "NUnit.Console": "3.4.1",
    "Microsoft.Dnx.TestHost": "1.0.0-rc1-final",
    "Microsoft.Dnx.Runtime": "1.0.0-rc1-final"
  },
  "testRunner": "nunit",
  "commands": {
    "Test": "earthworm.test"
  },

  "frameworks": {
    "dnx451": {}
  }
}

当我单击测试资源管理器中的全部运行按钮时,应该会找到我的所有测试,我得到以下输出:

Discovering tests in 'C:\Users\daniel\Repos\earthworm\test\earthworm.test\project.json' 

然后测试资源管理器中没有显示任何内容。 我试过查看Testing .NET Core using NUnit 3,所以看起来如果您使用的是最新的框架,它是可能的。我只想知道 dnx451 是如何做到这一点的。

【问题讨论】:

    标签: c# asp.net testing nunit


    【解决方案1】:

    您缺少对dotnet-test-nunit 和NUnit 的依赖,并且有许多不需要的引用。我真的很惊讶您能够使用该依赖项列表编写单元测试,但我猜 NUnit 被 NUnitLite 引入了。

    从这样的 project.json 开始,

    {
      "version": "1.0.0-*",
      "description": "Tests for the earthworm",
    
      "dependencies": {
        "earthworm": "1.0.0-*",
        "NSubstitute": "2.0.0-rc",
        "NUnit": "3.4.1",
        "dotnet-test-nunit": "3.4.0-beta-2"
      },
    
      "testRunner": "nunit",
    
      "frameworks": {
        "dnx451": {}
      }
    }
    

    【讨论】:

    • 嘿,Rob,谢谢你的帮助和很棒的文章。所以我使用了你给我的结构,我必须添加回 Nunitlite,以便主类中的自动运行功能能够正常工作,并将测试命令添加到 project.json 文件中。现在这适用于 dnx 但是如果我尝试在 Visual Studio 中使用 run all tests 我将无法加载应用程序或执行命令 Microsoft.dnx.testhosts 如果我将它添加回来,我会得到和我原来的帖子一样。
    • 听起来您正在尝试将 NUnitLite 自动运行与 .NET Core 运行器混合使用。我没有尝试过这种组合,但我的猜测是存在一些冲突。您也在运行 VS 2015 update 3 对吗?
    • 是的,我是。如果我们有你所建议的 project.json,我们是否不需要像Testing .NET Core using NUnit 3 中描述的那样拥有那个 Program.cs。我也遇到了 dotnet-test-nunit 的问题。一旦我将它添加到 project.json 并尝试构建,这是我得到的错误 项目earthworm.test 中的依赖项 Microsoft.NETCore.Platforms 1.0.1 不支持框架 DNX,Version=v4.5.1.
    • 啊,我认为netcore测试至少需要4.6.1,不确定
    • @DanielHorne 似乎是“3.4.0-beta-2”uinstall 中的一个错误,请改用“3.4.0-beta-1”
    【解决方案2】:

    如果以上都不适合你:

    如果您在发现或运行测试时遇到问题,您可能是 Visual Studio 中运行程序缓存损坏的受害者。要清除此缓存,请关闭 Visual Studio 的所有实例,然后删除文件夹 %TEMP%\VisualStudioTestExplorerExtensions。还要确保您的解决方案仅链接到单个版本的 Visual Studio 运行程序 NuGet 包 (xunit.runner.visualstudio)。

    发件人:http://xunit.github.io/docs/getting-started-dotnet-core.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2021-07-04
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多