XUnit Tests No Longer Working After Upgrade From .NET 5 To .NET 6 (Q & A)

Viewed 2575

I have an xUnit unit testing project. All was working fine in .NET 5.

In Visual Studio 2022, I changed the .NET Version in the csproj to .NET 6 as shown below.

enter image description here

Following this, the tests build but no longer run.

There is no info in the output window. The Test Explorer just says it wont run the tests, with 'unexpected error detected'.

enter image description here

What should I do to fix this?

2 Answers

I created a new project and compared the csproj file with my old project. There were a couple of differences

First, I needed to add the nuget package for Microsoft.NET.Test.Sdk (in my case, version 16.11.0). This seemed to fix it.

I also noticed a couple of properties in the first PropertyGroup that I was missing. I added those too. However, just adding Microsoft.NET.Test.Sdk fixed it for me.

enter image description here

In my case I was changing from NUnit to XUnit and also needed to add the xunit.runner.visualstudio nuget package

Related