dotnet 测试无法识别 xunit 测试

问题描述

我知道这个问题在我再次提出之前已经被问过多次,但是我仍然无法得到 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>

解决方法

我在 Windows 机器上工作,我做了以下工作以使其正常工作

  1. 关闭了我所有的 vscode/visual studio 实例
  2. 已删除 C:\Users\<username>\.nuget\packages 个文件夹
  3. 删除了 <projectname>.csproj 中 testrunner 包的引用

它又开始接受测试

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...