Lesson 06 of 93 · 6 min read · Updated
Microsoft.Testing.Platform vs VSTest: Running One xUnit v3 Project with Three Runners
On this page
A test framework and a test platform are two different things. The framework defines tests. The platform discovers and runs them. In .NET there are now two platforms: the classic VSTest and the newer Microsoft.Testing.Platform (MTP). This lesson runs the same xUnit v3 project in three ways, explains why the project switches MTP off by default, and shows what you need to change to move a whole repository to MTP.
Technical Requirements
- .NET 11 SDK (tested with SDK 11.0.100; projects target
net11.0) xunit.v34.0.3xunit.runner.visualstudio4.0.1 andMicrosoft.NET.Test.Sdk18.12.0 for the VSTest path
Framework vs Platform
xUnit, NUnit and MSTest give you attributes such as [Fact] and assertions such as Assert.Equal. They do not decide how a test process starts, how results are reported or how an IDE finds the tests. That is the job of the platform.
- VSTest is the long-standing platform behind
dotnet testand the Visual Studio Test Explorer. It needsMicrosoft.NET.Test.Sdkand a framework-specific adapter such asxunit.runner.visualstudio. - Microsoft.Testing.Platform (MTP) is a lighter platform that runs inside the test executable itself. No separate host process and no adapter package are needed.
xUnit v3 is designed for this model: a v3 test project is an executable, and the xunit.v3 package already contains an MTP runner.
The Project: MTP Switched Off on Purpose
M01.Foundations.XUnitV3Examples/M01.Foundations.XUnitV3Examples.csproj
Two properties control the behavior. IsTestingPlatformApplication decides whether the build produces an MTP application. UseMicrosoftTestingPlatformRunner decides whether the xUnit executable uses the MTP runner when it starts. Both are false here, and both can be overridden on the command line.
Same Project, Three Runners
The first command goes through VSTest. It uses Microsoft.NET.Test.Sdk and the xunit.runner.visualstudio adapter, exactly like every other test project in the solution. This is the path the IDE and the CI pipeline use.
The second command does not use dotnet test at all. It builds the project and starts the executable. Because MTP is off, the executable uses xUnit's own console runner, in the same process. No adapter and no test SDK take part.
The third command passes both properties as true. Now the executable starts the MTP runner, which prints its own output format and accepts MTP command-line options.
All three outputs report the same 6 passing tests. The tests did not change. Only the component that discovers and runs them changed.
Common Mistake: Mixing VSTest and MTP
Why not leave MTP on? xunit.v3 4.x is an MTP application by default. On the .NET 10 SDK and later, an MTP project does not run inside dotnet test when dotnet test is in VSTest mode. You get this error:
Every other test project in this solution uses VSTest. If this one project used MTP, dotnet test on the whole solution would fail. So the project turns MTP off and stays consistent with the rest. The rule is simple: use one platform per repository; do not run VSTest and MTP mixed. The choice of dotnet test mode is made for the whole solution, so a mixed solution always has one side that does not fit.
Is the "Zero Tests Ran" Problem Still There?
With SDK 10.0.400, switching a solution to MTP mode through global.json caused dotnet test to report "Zero tests ran" with exit code 5. With SDK 11.0.100 this problem did not reproduce. In a separate copy of the solution, global.json was set to the MTP runner and dotnet test --project was run against the v3 project. All 6 tests passed with exit code 0.
So moving a whole repository to xUnit v3 and MTP is now possible. The only reason to stay on VSTest in a large existing repository is consistency: hundreds of existing tests and the IDE and CI settings that already work with them.
Moving a Whole Repository to xUnit v3 and MTP
If you decide to migrate, do it for every test project at once:
- In the shared
Directory.Build.props, replacexunit,xunit.runner.visualstudioandMicrosoft.NET.Test.Sdkwith thexunit.v3package, and add<OutputType>Exe</OutputType>. - Update every
IAsyncLifetimeimplementation fromTasktoValueTask. - Add a
global.jsonfile at the solution root that selects the MTP runner (shown below). - Use the new
dotnet testsyntax on SDK 10 and later:dotnet test --project <proj>ordotnet test --solution <sln>.
global.json
After step 3, dotnet test no longer goes through VSTest for any project in the solution, so the switch is all or nothing. That is the same rule as before, seen from the other side.
Summary
- The framework defines tests; the platform (VSTest or Microsoft.Testing.Platform) discovers and runs them.
- An xUnit v3 project is an executable and can run through
dotnet test(VSTest),dotnet run(xUnit console runner) ordotnet runwith the MTP properties. xunit.v34.x is an MTP application by default; under VSTest-modedotnet teston SDK 10+ it fails unless you switch MTP off.- Use one platform per repository; do not mix VSTest and MTP projects in one solution.
- To move fully to MTP, change the packages, set
OutputTypetoExe, updateIAsyncLifetime, addglobal.jsonand usedotnet test --project.