|
1 | 1 | --- |
2 | | -title: Use Microsoft.Testing.Platform with `dotnet test` |
| 2 | +title: Use Microsoft.Testing.Platform with VSTest mode of `dotnet test` |
3 | 3 | description: Learn how to run Microsoft.Testing.Platform tests through dotnet test. |
4 | 4 | author: nohwnd |
5 | 5 | ms.author: jajares |
6 | | -ms.date: 12/20/2023 |
| 6 | +ms.date: 03/26/2025 |
7 | 7 | --- |
8 | 8 |
|
9 | | -# Use Microsoft.Testing.Platform with `dotnet test` |
| 9 | +# Use Microsoft.Testing.Platform with VSTest mode of `dotnet test` |
10 | 10 |
|
11 | | -This article describes how to use `dotnet test` to run tests when using `Microsoft.Testing.Platform`, and the various options that are available to configure the MSBuild output produced when running tests through Microsoft.Testing.Platform. |
| 11 | +This article describes `dotnet test` integration for Microsoft.Testing.Platform that is provided by Microsoft.Testing.Platform.MSBuild when running with VSTest mode of `dotnet test`. |
12 | 12 |
|
13 | | -This article shows how to use `dotnet test` to run all tests in a solution (_*.sln_) that uses `Microsoft.Testing.Platform`. |
| 13 | +Before reading this article, it's advised to read [Testing with dotnet test](unit-testing-with-dotnet-test.md) first. |
14 | 14 |
|
15 | | -## `dotnet test` integration |
| 15 | +By default, `dotnet test` is using VSTest behavior to run tests. To enable support for `Microsoft.Testing.Platform` in `dotnet test`, there are two options: |
16 | 16 |
|
17 | | -The [dotnet test](../tools/dotnet-test.md) command is a way to run tests from solutions, projects, or already built assemblies. [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md) hooks up into this infrastructure to provide a unified way to run tests, especially when migrating from VSTest to `Microsoft.Testing.Platform`. |
| 17 | +1. Use `dotnet test` in VSTest mode, and specify `<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>` MSBuild property in your project file. |
| 18 | +2. Use `dotnet test` in MTP mode, and enjoy more native support of MTP in `dotnet test`. This is only supported starting with .NET 10 SDK. |
18 | 19 |
|
19 | | -### `dotnet test` integration - VSTest mode |
20 | | - |
21 | | -`Microsoft.Testing.Platform` provides a [compatibility layer (VSTest Bridge)](./microsoft-testing-platform-extensions-vstest-bridge.md) to work with `dotnet test` seamlessly. |
22 | | - |
23 | | -Tests can be run by running: |
24 | | - |
25 | | -```dotnetcli |
26 | | -dotnet test |
27 | | -``` |
28 | | - |
29 | | -This layer runs test through VSTest and integrates with it on VSTest Test Framework Adapter level. |
30 | | - |
31 | | -### `dotnet test` - Microsoft.Testing.Platform mode |
32 | | - |
33 | | -By default, `dotnet test` is using VSTest behavior to run tests. You can enable support for `Microsoft.Testing.Platform` in `dotnet test` by specifying the `<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>` setting in your project file. |
34 | | - |
35 | | -```xml |
36 | | -<Project Sdk="Microsoft.NET.Sdk"> |
37 | | - |
38 | | - <PropertyGroup> |
39 | | - <TargetFramework>net8.0</TargetFramework> |
40 | | - <ImplicitUsings>enable</ImplicitUsings> |
41 | | - <Nullable>enable</Nullable> |
42 | | - |
43 | | - <IsPackable>false</IsPackable> |
44 | | - |
45 | | - <OutputType>Exe</OutputType> |
46 | | - <EnableMSTestRunner>true</EnableMSTestRunner> |
47 | | - |
48 | | - <!-- Add this to your project file. --> |
49 | | - <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport> |
50 | | - |
51 | | - </PropertyGroup> |
52 | | - |
53 | | - <!-- ... --> |
54 | | - |
55 | | -</Project> |
56 | | -``` |
57 | | - |
58 | | -> [!NOTE] |
59 | | -> It's highly recommended that you set the `TestingPlatformDotnetTestSupport` property in `Directory.Build.props`. That way, you don't have to add it to every test project file, and you don't risk introducing a new project that doesn't set this property and end up with a solution where some projects are VSTest while others are Microsoft.Testing.Platform, which may not work correctly and is unsupported scenario. |
| 20 | +Both of these options are explained in details in the [Testing with dotnet test](unit-testing-with-dotnet-test.md) article. |
60 | 21 |
|
61 | 22 | > [!IMPORTANT] |
62 | | -> Despite `TestingPlatformDotnetTestSupport` being set to `true`, most of the command line options defined in [dotnet test](../tools/dotnet-test.md) remain VSTest oriented and don't impact `Microsoft.Testing.Platform` based tests. To supply arguments to `Microsoft.Testing.Platform`, you need to use one of the methods described in [Microsoft.Testing.Platform command line arguments with dotnet test](#microsofttestingplatform-command-line-arguments-with-dotnet-test). |
63 | | -
|
64 | | -The list below described all `dotnet test` command line options that are supported by `Microsoft.Testing.Platform`: |
65 | | - |
66 | | -- `-a|--arch <ARCHITECTURE>` |
67 | | -- `--artifacts-path <ARTIFACTS_DIR>` |
68 | | -- `-c|--configuration <CONFIGURATION>` |
69 | | -- `-f|--framework <FRAMEWORK>` |
70 | | -- `-e|--environment <NAME="VALUE">` |
71 | | -- `--interactive` |
72 | | -- `--no-build` |
73 | | -- `--nologo` |
74 | | -- `--no-restore` |
75 | | -- `-o|--output <OUTPUT_DIRECTORY>` |
76 | | -- `--os <OS>` |
77 | | -- `-r|--runtime <RUNTIME_IDENTIFIER>` |
78 | | -- `-v|--verbosity <LEVEL>` |
79 | | - |
80 | | -These arguments are supported because they are linked to the build step and are independent of the testing platform used. |
81 | | - |
82 | | -### `Microsoft.Testing.Platform` command line arguments with `dotnet test` |
83 | | - |
84 | | -You can supply arguments that are used to call the testing application in one of the following ways: |
85 | | - |
86 | | -- Beginning with `Microsoft.Testing.Platform` version 1.4 (included with MSTest version 3.6), you can add options after the double dash `--` on the command line: |
87 | | - |
88 | | - ```dotnetcli |
89 | | - dotnet test -- --minimum-expected-tests 10 |
90 | | - ``` |
91 | | -
|
92 | | -- By using the `TestingPlatformCommandLineArguments` MSBuild property on the command line: |
93 | | -
|
94 | | - ```dotnetcli |
95 | | - dotnet test -p:TestingPlatformCommandLineArguments="--minimum-expected-tests 10" |
96 | | - ``` |
97 | | -
|
98 | | - Or in the project file: |
99 | | -
|
100 | | - ```xml |
101 | | - <PropertyGroup> |
102 | | - ... |
103 | | - <TestingPlatformCommandLineArguments>--minimum-expected-tests 10</TestingPlatformCommandLineArguments> |
104 | | - </PropertyGroup> |
105 | | - ``` |
106 | | - |
107 | | -## Additional MSBuild options |
108 | | - |
109 | | -The MSBuild integration provides options that can be specified in the project file or through global properties on the command line, such as `-p:TestingPlatformShowTestsFailure=true`. |
110 | | - |
111 | | -These are the available options: |
112 | | - |
113 | | -- [Show failure per test](#show-failure-per-test) |
114 | | -- [Show complete platform output](#show-complete-platform-output) |
| 23 | +> The remaining of this article is specific to the first option. |
115 | 24 |
|
116 | | -### Show failure per test |
| 25 | +## Show failure per test |
117 | 26 |
|
118 | 27 | By default, test failures are summarized into a _.log_ file, and a single failure per test project is reported to MSBuild. |
119 | 28 |
|
@@ -152,7 +61,7 @@ Or in project file: |
152 | 61 | </Project> |
153 | 62 | ``` |
154 | 63 |
|
155 | | -### Show complete platform output |
| 64 | +## Show complete platform output |
156 | 65 |
|
157 | 66 | By default, all console output that the underlying test executable writes is captured and hidden from the user. This includes the banner, version information, and formatted test information. |
158 | 67 |
|
|
0 commit comments