【问题标题】:dotnet test does not recognize xunit testsdotnet test 无法识别 xunit 测试
【发布时间】:2021-01-22 20:50:48
【问题描述】:

我知道这个问题在我再次提出之前已经被问过多次,但是我仍然无法得到 dotnet 5.0 和 xunit 的答案

我尝试了什么。

  • 我定义了以下测试
public class IntegrationTests
{
    [Theory]
    [MemberData(nameof(Tests), MemberType = typeof(IntegrationTests))]
    public void Test(IntegrationTest test)
    {
       Assert.True(test.Expected, test.Actual);
    }
}
  • Visual Studio 2019 可以识别所有测试并毫无问题地运行它们
  • dotnet 测试命令说
dotnet test <path to>.csproj

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in C:\<path>\bin\Debug\net5.0\<projectname>.dll. 
Make sure that test discoverer & executors are registered and platform & framework 
version settings are appropriate and try again.

我不完全理解这里的“测试发现者和执行者”是什么意思。

我的 .csproj 文件具有以下 nuget 包(因为通过添加其中之一解决了许多类似问题)

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.console" Version="2.4.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

【问题讨论】:

    标签: xunit .net-5 dotnet-test


    【解决方案1】:

    我在一台 Windows 机器上工作,我做了以下工作来使它工作

    1. 关闭了我所有的 vscode/visual studio 实例
    2. 已删除C:\Users\&lt;username&gt;\.nuget\packages 文件夹
    3. &lt;projectname&gt;.csproj 中删除了测试运行程序包的引用

    它又开始接受测试了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 2017-07-04
      • 2012-11-21
      • 2021-07-17
      相关资源
      最近更新 更多