Training
Module
C# testing in Visual Studio - Training
Start testing your C# apps by using the testing tools in Visual Studio. Learn to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article will provide you with insights into the dotnet test
CLI command, its history, and its compatibility with both VSTest and Microsoft.Testing.Platform (MTP).
The dotnet test
command operates in two primary modes:
dotnet test
and was the only mode available before the .NET 10 SDK. It is primarily designed for VSTest but can also run Microsoft.Testing.Platform test via Microsoft.Testing.Platform.MSBuild NuGet package.Tip
For CLI reference, see dotnet test.
For an extended period, VSTest has been the only test platform in .NET. Consequently, dotnet test was exclusively designed for VSTest, with all command-line options tailored to VSTest.
The process involves invoking the VSTest
MSBuild target, which triggers other internal targets to run and ultimately runs vstest.console. This translates all dotnet test
command-line options to their equivalents in vstest.console.
dotnet test
is typically designed to run VSTest projects in VSTest mode, as that was its original purpose. However, to run MTP projects in VSTest mode, you can use the Microsoft.Testing.Platform.MSBuild. From the user's perspective, this support is enabled by setting the TestingPlatformDotnetTestSupport
MSBuild property to true (it is false by default for backward compatibility reasons). In simple terms, setting this property to true will cause Microsoft.Testing.Platform.MSBuild to change the VSTest
target behavior, redirecting it to call InvokeTestingPlatform
. This is an MSBuild target included in Microsoft.Testing.Platform.MSBuild, responsible for correctly running MTP test applications as executables.
This means that VSTest-specific command-line options are silently ignored in this mode, such as --logger
.
This implies that there should be a way to pass MTP-specific command-line options, such as --report-trx
, which is equivalent to using --logger trx
in VSTest. Given the current limitations of the dotnet test
CLI, the only way to include MTP-specific arguments is by appending them after an additional --
. For instance, dotnet test -- --report-trx
.
In dotnet test
VSTest mode, the --
is used to indicate the RunSettings arguments. Originally, dotnet test
was designed to pass those arguments as an MSBuild property called VSTestCLIRunSettings
. Therefore, when running MTP test applications in VSTest mode, we repurpose the value of VSTestCLIRunSettings
to represent the "application arguments".
When running dotnet test
in VSTest mode, it is recommended to avoid including both VSTest and Microsoft.Testing.Platform in the same solution.
This scenario is not officially supported, and you should be aware of the following:
--
will be treated as RunSettings arguments for VSTest projects.dotnet test
VSTest mode, you should use Microsoft.Testing.Platform.MSBuild
, pass MTP-specific command-line options after the extra --, and set TestingPlatformDotnetTestSupport
to true.dotnet test
mode specifically designed for MTP. We encourage MTP users to transition from the VSTest dotnet test
mode to the new mode with the .NET 10 SDK.To address the issues encountered when running dotnet test
with MTP in VSTest mode, we introduced a new mode in the .NET 10 SDK that is specifically designed for MTP.
To enable this mode, you should add a dotnet.config
file to the root of the repository or solution.
[dotnet.test:runner]
name = "Microsoft.Testing.Platform"
Since this mode is specifically designed for Microsoft.Testing.Platform, neither TestingPlatformDotnetTestSupport
nor the additional --
are required.
Important
This mode is only compatible with Microsoft.Testing.Platform version 1.7.0 and later.
Important
If your test project supports VSTest but does not support MTP, an error will be generated.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
C# testing in Visual Studio - Training
Start testing your C# apps by using the testing tools in Visual Studio. Learn to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.