问题描述
我知道这个问题在我再次提出之前已经被问过多次,但是我仍然无法得到 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 机器上工作,我做了以下工作以使其正常工作
- 关闭了我所有的 vscode/visual studio 实例
- 已删除
C:\Users\<username>\.nuget\packages
个文件夹 - 删除了
<projectname>.csproj
中 testrunner 包的引用
它又开始接受测试