frictionlesspulley
frictionlesspulley

Reputation: 12358

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.

public class IntegrationTests
{
    [Theory]
    [MemberData(nameof(Tests), MemberType = typeof(IntegrationTests))]
    public void Test(IntegrationTest test)
    {
       Assert.True(test.Expected, test.Actual);
    }
}
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.

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>

Upvotes: 5

Views: 5250

Answers (3)

AnalogThinker
AnalogThinker

Reputation: 31

Using built-in Nuget Package Manager's feature "Update All Packages" - credit goes to answer by shA.t in Install a Nuget package in Visual Studio Code Steps:

  • Close all VSCode instances
  • Delete C:\Users<username>.nuget\packages folder
  • Open the built-in Nuget Package Manager (CTRL+SHIFT+P)
  • Click the "Update All Packages" button on right
  • Edit the file <solution__folder>.vscode\settings.json
  • Set testProjectPath property to { "dotnet-test-explorer.testProjectPath": "**/*Tests.csproj"} (or whatever pattern you use to name your test projects)
  • Run dotnet build
  • Run dotnet test

Upvotes: 0

Andrey Mateus
Andrey Mateus

Reputation: 1

Step 1 - Remove all references in the .csproj file

Step 2 - Run the command: dotnet restore

Step 3 - Run dotnet build

Step 4 - Add references again

Step 5 - Run dotnet restore

Step 6 - Run the dotnet test

Step 7 - have fun

Note: Use Control + X(Cut) to remove the references so you can paste them back in step 4. =)

Upvotes: 0

frictionlesspulley
frictionlesspulley

Reputation: 12358

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>\.nuget\packages folder
  3. Deleted references for testrunner packages in <projectname>.csproj

and it started picking up the tests again

Upvotes: 3

Related Questions