Microsoft.Testing.Platform
is a lightweight and portable alternative to VSTest for running tests in command line, in continuous integration (CI) pipelines, in Visual Studio Test Explorer, and in Visual Studio Code. In this article, you learn the key differences between Microsoft.Testing.Platform and VSTest.
Tests are executed in different ways depending on the runner.
Execute VSTest testsVSTest ships with Visual Studio, the .NET SDK, and as a standalone tool in the Microsoft.TestPlatform NuGet package. VSTest uses a runner executable to run tests, called vstest.console.exe
, which can be used directly or through dotnet test
.
Microsoft.Testing.Platform is embedded directly into your test project and doesn't ship any extra executables. When you run your project executable, your tests run. For more information on running Microsoft.Testing.Platform tests, see Microsoft.Testing.Platform overview: Run and debug tests.
Namespaces and NuGet packagesTo familiarize yourself with Microsoft.Testing.Platform
and VSTest, it's helpful to understand the namespaces and NuGet packages that are used by each.
VSTest is a collection of testing tools that are also known as the Test Platform. The VSTest source code is open-source and available in the microsoft/vstest GitHub repository. The code uses the Microsoft.TestPlatform.*
namespace.
VSTest is extensible and common types are placed in Microsoft.TestPlatform.ObjectModel NuGet package.
Microsoft.Testing.Platform namespacesMicrosoft.Testing.Platform is based on Microsoft.Testing.Platform NuGet package and other libraries in the Microsoft.Testing.*
namespace. Like VSTest, the Microsoft.Testing.Platform
is open-source and has a microsoft/testfx GitHub repository.
Note
The Visual Studio Test Explorer supports the Microsoft.Testing.Platform protocol since 17.12 onward. If you run/debug your tests using earlier versions of Visual Studio, Test Explorer will use vstest.console.exe
and the old protocol to run these tests.
Microsoft.Testing.Platform uses a JSON-RPC based protocol to communicate between Visual Studio and the test runner process. The protocol is documented in the MSTest GitHub repository.
VSTest also uses a JSON based communication protocol, but it's not JSON-RPC based.
Disabling the new protocolTo disable the use of the new protocol in Test Explorer, you can edit your project to add the following property: <DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
.
You can also go to Preview Features options in Visual Studio and deselect the "Use testing platform server mode" option.
ExecutablesVSTest ships multiple executables, notably vstest.console.exe
, testhost.exe
, and datacollector.exe
. However, MSTest is embedded directly into your test project and doesn't ship any other executables. The executable your test project compiles to is used to host all the testing tools and carry out all the tasks needed to run tests.
In addition to the steps specific to your test framework, you need to update your test infrastructure to accommodate to Microsoft.Testing.Platform
.
dotnet test
Command line options of dotnet test
are divided into 2 categories: build related arguments and test related ones.
The build related arguments are passed to the dotnet build
command and as such don't need to be updated for the new platform. Build related arguments are listed below:
-a|--arch <ARCHITECTURE>
--artifacts-path <ARTIFACTS_DIR>
-c|--configuration <CONFIGURATION>
-f|--framework <FRAMEWORK>
-e|--environment <NAME="VALUE">
--interactive
--no-build
--nologo
--no-restore
-o|--output <OUTPUT_DIRECTORY>
--os <OS>
-r|--runtime <RUNTIME_IDENTIFIER>
-v|--verbosity <LEVEL>
The test related arguments are VSTest specific and so need to be transformed to match the new platform. The following table shows the mapping between the VSTest arguments and the new platform:
VSTest argument New platform argument--test-adapter-path <ADAPTER_PATH>
Not supported --blame
Not supported --blame-crash
--crashdump
requires Crash dump extension --blame-crash-dump-type <DUMP_TYPE>
--crashdump-type
requires Crash dump extension --blame-crash-collect-always
Not supported --blame-hang
--hangdump
requires Hang dump extension --blame-hang-dump-type <DUMP_TYPE>
--hangdump-type
requires Hang dump extension --blame-hang-timeout <TIMESPAN>
--hangdump-timeout
requires Hang dump extension --collect <DATA_COLLECTOR_NAME>
Depends on the data collector -d\|--diag <LOG_FILE>
--diagnostic
--filter <EXPRESSION>
Depends upon the selected test framework -l\|--logger <LOGGER>
Depends on the logger --results-directory <RESULTS_DIR>
--results-directory <RESULTS_DIR>
-s\|--settings <SETTINGS_FILE>
Depends upon the selected test framework -t\|--list-tests
--list-tests
-- <RunSettings arguments>
--test-parameter
(provided by VSTestBridge)
Important
Before specifying any Microsoft.Testing.Platform
arguments, you need to add --
to separate the dotnet test
arguments from the new platform arguments. For example, dotnet test --no-build -- --list-tests
.
vstest.console.exe
If you are using vstest.console.exe
directly, we recommend replacing it with the dotnet test
command.
When using Visual Studio or Visual Studio Code Test Explorer, you might need to enable the support for the new test platform.
Visual StudioVisual Studio Test Explorer supports the new test platform starting with version 17.14. If you are using an earlier version, you might need to update your Visual Studio to the latest version.
Visual Studio CodeVisual Studio Code with C# DevKit supports the new test platform.
Azure DevOpsWhen using Azure DevOps tasks, you might need to update your pipeline to use the new test platform.
VSTest taskIf you're using the VSTest task in Azure DevOps, you can replace it with the .NET Core task.
.NET Core taskIf you're using the .NET Core task, no changes are needed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4