1

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

1 回答 1

1

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

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

它又开始接受测试

于 2021-01-25T17:47:24.937 回答