-
Notifications
You must be signed in to change notification settings - Fork 6k
Testing docs improvements #48494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Youssef1313
wants to merge
4
commits into
main
Choose a base branch
from
dev/ygerges/testing-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−77
Open
Testing docs improvements #48494
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
docs/core/testing/migrating-vstest-microsoft-testing-platform.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
--- | ||
title: Migration guide from VSTest to Microsoft.Testing.Platform | ||
description: Learn how to migrate from VSTest to Microsoft.Testing.Platform | ||
author: Youssef1313 | ||
ms.author: ygerges | ||
ms.date: 09/15/2025 | ||
--- | ||
|
||
# Migration guide from VSTest to Microsoft.Testing.Platform | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In this article, you'll learn how to migrate from VSTest to Microsoft.Testing.Platform. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Opt-in to use Microsoft.Testing.Platform | ||
|
||
The first step in the migration is to opt-in to using Microsoft.Testing.Platform. | ||
|
||
For all test frameworks, add `<OutputType>Exe</OutputType>` to all test projects in the solution. After that, follow the framework-specific guidance. | ||
|
||
### MSTest | ||
|
||
Microsoft.Testing.Platform is supported by MSTest starting with 3.2.0. However, we recommend updating to the latest available MSTest version. | ||
|
||
To opt-in, add `<EnableMSTestRunner>true</EnableMSTestRunner>` under a `PropertyGroup` in [`Directory.Build.props`](/visualstudio/msbuild/customize-by-directory) file. | ||
|
||
> [!NOTE] | ||
> When using MSTest.Sdk, Microsoft.Testing.Platform is used by default, unless `<UseVSTest>true</UseVSTest>` is specified. | ||
|
||
### NUnit | ||
|
||
Microsoft.Testing.Platform is supported by NUnit3TestAdapter starting with 5.0.0. | ||
|
||
To opt-in, add `<EnableNUnitRunner>true</EnableNUnitRunner>` under a `PropertyGroup` in [`Directory.Build.props`](/visualstudio/msbuild/customize-by-directory) file. | ||
|
||
### xUnit.net | ||
|
||
Microsoft.Testing.Platform is supported starting with xunit.v3. | ||
|
||
To opt-in, add `<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>` under a `PropertyGroup` in [`Directory.Build.props`](/visualstudio/msbuild/customize-by-directory) file. | ||
|
||
## `dotnet test` | ||
|
||
### Opt-in for .NET 9 SDK and earlier | ||
|
||
In .NET 9 SDK and earlier, there is no *native* support for Microsoft.Testing.Platform for `dotnet test`. However, we provide support that is built on top of VSTest infrastructure. To use that, add `<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>` under a `PropertyGroup` in [`Directory.Build.props`](/visualstudio/msbuild/customize-by-directory) file. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
> [!IMPORTANT] | ||
> When running Microsoft.Testing.Platform support in this mode, you need to add `--` to separate the `dotnet test` arguments from the new platform arguments. For example, `dotnet test --no-build -- --list-tests`. | ||
|
||
### Opt-in for .NET 10 SDK and later | ||
|
||
Starting with .NET 10 SDK, there is *native* support for Microsoft.Testing.Platform. To use it, you must specify the test runner as `Microsoft.Testing.Platform` in *global.json*: | ||
|
||
```json | ||
{ | ||
"test": { | ||
"runner": "Microsoft.Testing.Platform" | ||
} | ||
} | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> In this mode, the extra `--` is no longer used. | ||
|
||
### Update `dotnet test` invocations | ||
|
||
Command line options of `dotnet test` are divided into 2 categories: build related arguments and test related ones. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The build related arguments are irrelevant to the test platform and as such don't need to be updated for the new platform. Build related arguments are listed below: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `-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: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
| VSTest argument | New platform argument | | ||
|-----------------|-----------------------| | ||
| `--test-adapter-path <ADAPTER_PATH>` | Not relevant for Microsoft.Testing.Platform | | ||
| `--blame` | Not relevant for Microsoft.Testing.Platform | | ||
| `--blame-crash` | `--crashdump` (requires [Crash dump extension](./microsoft-testing-platform-extensions-diagnostics.md#crash-dump)) | | ||
| `--blame-crash-dump-type <DUMP_TYPE>` | `--crashdump-type` (requires [Crash dump extension](./microsoft-testing-platform-extensions-diagnostics.md#crash-dump)) | | ||
| `--blame-crash-collect-always` | Not supported | | ||
| `--blame-hang` | `--hangdump` (requires [Hang dump extension](./microsoft-testing-platform-extensions-diagnostics.md#hang-dump)) | | ||
| `--blame-hang-dump-type <DUMP_TYPE>` | `--hangdump-type` (requires [Hang dump extension](./microsoft-testing-platform-extensions-diagnostics.md#hang-dump)) | | ||
| `--blame-hang-timeout <TIMESPAN>` | `--hangdump-timeout` (requires [Hang dump extension](./microsoft-testing-platform-extensions-diagnostics.md#hang-dump)) | | ||
| `--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](microsoft-testing-platform-extensions-vstest-bridge.md)) | | ||
|
||
#### `--collect` | ||
|
||
`--collect` is a general extensibility point in VSTest for any data collector. The extensibility model of Microsoft.Testing.Platform is different and there is no such centralized argument to be used by all data collectors. With Microsoft.Testing.Platform, each data collector can add its own command-line option. For example, running Microsoft CodeCoverage through VSTest can be similar to the following: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dotnetcli | ||
dotnet test --collect "Code Coverage;Format=cobertura" | ||
``` | ||
|
||
With Microsoft.Testing.Platform, this becomes: | ||
|
||
```dotnetcli | ||
dotnet test --coverage --coverage-output-format cobertura | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> As explained earlier, when using Microsoft.Testing.Platform with the VSTest-based `dotnet test`, extra `--` is needed before the arguments intended to be passed to the platform. | ||
> So, this becomes `dotnet test -- --coverage --coverage-output-format cobertura`. | ||
|
||
#### `--filter` | ||
|
||
`--filter` is the VSTest-based filter. This is supported by MSTest and NUnit even when running with Microsoft.Testing.Platform. However, for xUnit.net, this is no longer supported when running with Microsoft.Testing.Platform. You must migrate from the VSTest-based filter to the new filter support in xunit.v3 which is provided using the following command-line options: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `--filter-class` | ||
- `--filter-not-class` | ||
- `--filter-method` | ||
- `--filter-not-method` | ||
- `--filter-namespace` | ||
- `--filter-not-namespace` | ||
- `--filter-trait` | ||
- `--filter-not-trait` | ||
- `--filter-query` | ||
|
||
For more information, see [Microsoft.Testing.Platform documentation for xUnit.net](https://xunit.net/docs/getting-started/v3/microsoft-testing-platform) and [Query Filter Language for xUnit.net](https://xunit.net/docs/query-filter-language). | ||
|
||
#### `--logger` | ||
|
||
What was usually referred to as "logger" in VSTest is referred to as "reporter" in Microsoft.Testing.Platform. In Microsoft.Testing.Platform, logging is explicitly for diagnosing purposes only. | ||
|
||
Similar to `--collect`, `--logger` is a general extensibility point in VSTest for any logger (what we call reporter in the context of Microsoft.Testing.Platform). Each Microsoft.Testing.Platform reporter is free to add its own command-line option, and as such there is no centralized command-line option similar to VSTest's `--logger`. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
One of the very commonly used VSTest loggers is the TRX logger. This was usually called as follows: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dotnetcli | ||
dotnet test --logger trx | ||
``` | ||
|
||
With Microsoft.Testing.Platform, this becomes: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dotnetcli | ||
dotnet test --report-trx | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> In order to use `--report-trx`, you must have `Microsoft.Testing.Extensions.TrxReport` NuGet package. | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
> [!IMPORTANT] | ||
> As explained earlier, when using Microsoft.Testing.Platform with the VSTest-based `dotnet test`, extra `--` is needed before the arguments intended to be passed to the platform. | ||
> So, this becomes `dotnet test -- --report-trx`. | ||
|
||
#### `--settings` | ||
|
||
VSTest's `--settings` is used to specify a RunSettings file for the test run. RunSettings isn't supported by the core Microsoft.Testing.Platform and was replaced by a more modern [`testconfig.json`](./microsoft-testing-platform-config.md) configuration file. However, MSTest and NUnit still support the old RunSettings when running Microsoft.Testing.Platform and `--settings` is still supported. | ||
|
||
## `vstest.console.exe` | ||
|
||
If you are using `vstest.console.exe` directly, we recommend replacing it with the `dotnet test` command. | ||
|
||
## Test Explorer | ||
|
||
When using Visual Studio or Visual Studio Code Test Explorer, you might need to enable the support for Microsoft.Testing.Platform. | ||
|
||
### Visual Studio | ||
|
||
Visual Studio Test Explorer supports Microsoft.Testing.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 Code | ||
|
||
Visual Studio Code with C# DevKit supports Microsoft.Testing.Platform. | ||
|
||
## Azure DevOps | ||
|
||
When using Azure DevOps tasks, you might need to update your pipeline to use Microsoft.Testing.Platform, depending on which task you use. | ||
|
||
### VSTest task | ||
|
||
If you're using the [VSTest task](/azure/devops/pipelines/tasks/reference/vstest-v3) in Azure DevOps, you can replace it with the [.NET Core task](/azure/devops/pipelines/tasks/reference/dotnet-core-cli-v2). | ||
|
||
### .NET Core CLI task | ||
|
||
1. If you have custom `arguments` passed to the task, this needs to follow the same guidance as the `dotnet test` migration guidance. | ||
1. If you're using the [DotNetCoreCLI](/azure/devops/pipelines/tasks/reference/dotnet-core-cli-v2) task without opting-in the native Microsoft.Testing.Platform experience for .NET 10 SDK and later via `global.json` file, you need to set the task `arguments` to correctly point to the results directory it used to point to, as well as requested TRX report. For example: | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```yml | ||
- task: DotNetCoreCLI@2 | ||
displayName: Run unit tests | ||
inputs: | ||
command: 'test' | ||
arguments: '-- --report-trx --results-directory $(Agent.TempDirectory) | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.