6

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>\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> 

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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. =)

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.