Xunit 单元测试不会 运行

Xunit Unit Tests will not run

我完全被这个问题困住了。所以我的团队在服务测试项目中有一个单元测试项目。测试是在测试资源管理器窗格中发现的,但是当我尝试 运行 测试时,我得到了这些错误:

'Multiple test adapters with the same uri 'executor://xunit/VsTestRunner2' were found. Ignoring adapter 'Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner'. Please uninstall the conflicting adapter(s) to avoid this warning'

'[xUnit.net 00:00:00.0251250] Skipping: (could not find dependent assembly 'Microsoft.Extensions.DependencyModel, Version=1.1.0')'

'No test is available in C:\. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.'

上下文信息:

我的测试项目project.json:

{
   "version": "1.0.0-*",
   "testRunner": "xunit",
    "dependencies": {
       "dotnet-test-xunit": "2.2.0-preview2-build1029",
       "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.1.3",
       "Microsoft.DiaSymReader": "1.0.8",
       "Microsoft.DiaSymReader.Native": "1.4.1",
       "Microsoft.Extensions.Logging.Abstractions": "1.1.2",
       "Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview2-003121",
       "Newtonsoft.Json": "9.0.1",
       "WebServices": "1.0.0-*",
       "xunit": "2.2.0",
       "xunit.abstractions": "2.0.1",
       "xunit.assert": "2.2.0",
       "xunit.core": "2.2.0",
       "xunit.extensibility.core": "2.2.0",
       "xunit.extensibility.execution": "2.2.0",
       "xunit.runner.utility": "2.2.0"
   },
   "frameworks": {
    "net461": {
        "dependencies": {
            "Microsoft.NETCore.Platforms": "1.1.0"
        }
    }
}

奇怪的是它对我的团队成员有效。但不是我。我们环境中的差异是:来自 Windows 和 Visual Studio 的最新更新,而它们落后一两个更新。

有人知道解决方法吗?

我遇到了同样的问题,我通过将 Visual Studio 2017 从 15.5.2 更新到 15.5.4 并更新我的测试项目引用来修复它:

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

至:

<ItemGroup>
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

并重新启动 Visual Studio(显然 VS 缓存并使用以前的版本,即使在您更新后也是如此)。

不确定这 3 个问题中的一个或它们的组合是否修复了它。

我遇到了同样的问题,但我已经安装了 Visual Studio 2017 15.5.4。为了使其正常工作,我更新了所有 xunit 相关参考资料,现在我的 .csproj 相关参考资料如下所示:

<ItemGroup>
   <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
   <PackageReference Include="xunit" Version="2.3.1" />
   <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

不太确定什么不起作用,但我的建议是确保这些引用在 csproj 中并具有这些最低版本。

安装或更新 "xunit.runner.visualstudio" 包对我有用。在那之前,它无法使用框架 462。

我遇到了与您类似的问题,说明 could not find dependent assembly;实际上,该程序集在那里并且可供 xUnit VS 运行ner 使用。但是,实际问题是什么,我将 Visual Studio 设置为默认使用 32bit 测试 运行ner。它找不到的 'dependent assembly' 只是处理器架构与正在使用的 xUnit 测试 运行 不同。

要修复,如 here 所述,从 Visual Studio 菜单转到 Test -> Test Settings -> Default Processor Architecture 并将其设置为 X64(如果您使用的是 64bit)程序集,或者 X86 如果您使用的是 32bit 程序集。 xUnit VS 运行ner 给出的错误对于尝试调试此问题非常具有误导性。

我在新机器上安装 Visual Studio 时遇到了这个问题。测试将在 Visual Studio 中的我的台式机上进行 运行,但不会在我的笔记本电脑上进行。

关闭并重新打开 Visual Studio 适合我。

如果您在同一个 Visual Studio(或 Visual Studio 的任何其他实例)上有一个项目 运行,请停止它。虽然我知道这很尴尬,但它解决了这个问题。

我遇到了同样的问题,我安装了以下 nuget 包

 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
  <PackageReference Include="xunit" Version="2.4.1" />
  <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

最近在VS 2019上遇到了这个问题。 安装 VS.QualityTools.UnitTestFramework nuget 解决了问题

如果您在 Visual Studio 中的问题是测试运行程序输出似乎为空,请检查相关按钮(下方的白框)是否全部选中。