gpt4 book ai didi

xunit - dotnet 测试无法识别 xunit 测试

转载 作者:行者123 更新时间:2023-12-05 04:54:11 28 4
gpt4 key购买 nike

I know that this question has been asked multiple times before I raise it again, However I still could not get the answer for dotnet 5.0 and 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 中删除了对测试运行程序包的引用

它又开始接受测试了

关于xunit - dotnet 测试无法识别 xunit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65852592/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com