xUnit.v3 got a new major release. This blog post is more about the consequences of that for your local build and CI/CD pipelines than about the new features.
v4.0.0
Check the release notes here: https://xunit.net/releases/v3/4.0.0
The important part:
With 4.0, we are discontinuing official support for Microsoft Testing Platform v1. The default version of Microsoft Testing Platform support now is v2
MTP - Microsoft Testing Platform
The Microsoft Testing Platform is the engine behind Visual Studio Test Explorer and the dotnet test command. Before we have the VSTest Platform, now we have that!
That is cool, but can lead to issues if you just upgrade. After a fresh upgrade to xUnit.v3 4.0.0 you might get something like:
error : Testing with VSTest target is no longer supported by Microsoft.Testing.Platform on .NET 10 SDK and later. If you use dotnet test, you should opt-in to the new dotnet test experience. For more information, see https://aka.ms/dotnet-test-mtp-error [/path/to/your/csproj]
The issue is that you have to instruct the SDK (I am on .NET 10 SDK) to use the new MTP v2.
global.json to the rescue
You can read the nits and bits here: https://learn.microsoft.com/en-us/dotnet/core/testing/microsoft-testing-platform-migration-from-v1-to-v2
But to opt-in into MTP-based implementation, either extend your global.json or create one in the root of your solution with the following content:
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
If you run your application now locally, via dotnet test it runs nicely! But as soon as you push it, you might run into trouble. For example for one of my customers projects we are using Azure DevOps with the "normal" DotNetCoreCLI@2 task.
Azure DevOps Fix
Let's have a quick look at: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test#migrate-to-mtp-mode-of-dotnet-test under Point 5:
If passing a specific solution (or directory containing solution), for example, dotnet test MySolution.sln, this should become dotnet test --solution MySolution.sln
If you use DotNetCoreCLI@2 task, then it just does not do that! So it will still not work. That is specific to MTP v2! Check out the issue here: https://developercommunity.azure.com/t/11042906
The remedy is basically use your good old bash and call dotnet test --solution MySolution.sln instead of using the DotNetCoreCLI@2 task.