Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

.net 5 - dotnet test does not recognize xunit tests

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

What have I tried.

  • I have the following test defined
public class IntegrationTests
{
    [Theory]
    [MemberData(nameof(Tests), MemberType = typeof(IntegrationTests))]
    public void Test(IntegrationTest test)
    {
       Assert.True(test.Expected, test.Actual);
    }
}
  • Visual Studio 2019 recognizes all the tests and runs them without any issues
  • dotnet test command says
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>inDebug
et5.0<projectname>.dll. 
Make sure that test discoverer & executors are registered and platform & framework 
version settings are appropriate and try again.

I don't fully undertand what "test discoverer and executors mean here.

My .csproj file has following nuget packages (since many of the similar questions got resolved by adding one of these)

    <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>
question from:https://stackoverflow.com/questions/65852592/dotnet-test-does-not-recognize-xunit-tests

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was working on a windows machine and I did the following to make it work

  1. Closed all my vscode / visual studio instances
  2. Deleted C:Users<username>.nugetpackages folder
  3. Deleted references for testrunner packages in <projectname>.csproj

and it started picking up the tests again


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...