You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
9
-
10
8
## Name
11
9
12
10
`dotnet test` - .NET test driver used to execute unit tests.
13
11
14
-
## Synopsis
12
+
## Description
13
+
14
+
The `dotnet test` command builds the solution and runs the tests with either VSTest or Microsoft Testing Platform (MTP). To enable MTP, you need to add a config file named `dotnet.config` with TOML format located at the root of the solution or repository.
15
+
16
+
Some examples of the `dotnet.config` file:
17
+
18
+
```toml
19
+
[dotnet.test:runner]
20
+
name = "MicrosoftTestingPlatform"
21
+
```
22
+
23
+
```toml
24
+
[dotnet.test:runner]
25
+
name = "VSTest"
26
+
```
27
+
28
+
## VSTest and Microsoft Testing Platform (MTP)
29
+
30
+
### [dotnet test with VSTest](#tab/dotnet-test-with-vstest)
31
+
32
+
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
The `dotnet test` command is used to execute unit tests in a given solution. The `dotnet test` command builds the solution and runs a test host application for each test project in the solution using `VSTest`. The test host executes tests in the given project using a test framework, for example: MSTest, NUnit, or xUnit, and reports the success or failure of each test. If all tests are successful, the test runner returns 0 as an exit code; otherwise if any test fails, it returns 1.
55
75
@@ -64,13 +84,13 @@ Test projects specify the test runner using an ordinary `<PackageReference>` ele
64
84
65
85
Where `Microsoft.NET.Test.Sdk` is the test host, `xunit` is the test framework. And `xunit.runner.visualstudio` is a test adapter, which allows the xUnit framework to work with the test host.
@@ -82,7 +102,7 @@ Where `Microsoft.NET.Test.Sdk` is the test host, `xunit` is the test framework.
82
102
83
103
If not specified, the effect is the same as using the `DIRECTORY` argument to specify the current directory.
84
104
85
-
## Options
105
+
####Options
86
106
87
107
> [!WARNING]
88
108
> Breaking changes in options:
@@ -252,7 +272,7 @@ Where `Microsoft.NET.Test.Sdk` is the test host, `xunit` is the test framework.
252
272
253
273
For more information, see [Passing RunSettings arguments through command line](https://github.com/Microsoft/vstest-docs/blob/main/docs/RunSettingsArguments.md).
254
274
255
-
## Examples
275
+
####Examples
256
276
257
277
- Run the tests in the project in the current directory:
258
278
@@ -342,7 +362,7 @@ Where `Microsoft.NET.Test.Sdk` is the test host, `xunit` is the test framework.
342
362
dotnet test ~/projects/test1/test1.csproj -p:TestTfmsInParallel=false
343
363
```
344
364
345
-
## Filter option details
365
+
####Filter option details
346
366
347
367
`--filter <EXPRESSION>`
348
368
@@ -380,8 +400,208 @@ You can enclose expressions in parenthesis when using conditional operators (for
380
400
381
401
For more information and examples on how to use selective unit test filtering, see [Running selective unit tests](../testing/selective-unit-tests.md).
382
402
383
-
## See also
403
+
####See also
384
404
385
405
-[Frameworks and Targets](../../standard/frameworks.md)
-[Passing runsettings arguments through commandline](https://github.com/microsoft/vstest/blob/main/docs/RunSettingsArguments.md)
408
+
409
+
### [dotnet test with MTP](#tab/dotnet-test-with-mtp)
410
+
411
+
**This article applies to:** ✔️ .NET 10 SDK and later versions
412
+
413
+
#### Synopsis
414
+
415
+
```dotnetcli
416
+
dotnet test
417
+
[--project <PROJECT_PATH>]
418
+
[--solution <SOLUTION_PATH>]
419
+
[--directory <DIRECTORY_PATH>]
420
+
[--test-modules <EXPRESSION>]
421
+
[--root-directory <ROOT_PATH>]
422
+
[--list-tests]
423
+
[--max-parallel-test-modules <NUMBER>]
424
+
[-a|--arch <ARCHITECTURE>]
425
+
[-c|--configuration <CONFIGURATION>]
426
+
[-f|--framework <FRAMEWORK>]
427
+
[--os <OS>]
428
+
[-r|--runtime <RUNTIME_IDENTIFIER>]
429
+
[-v|--verbosity <LEVEL>]
430
+
[--no-build]
431
+
[--no-restore]
432
+
[--no-ansi]
433
+
[--no-progress]
434
+
[--output <VERBOSITY_LEVEL>]
435
+
[<args>...]
436
+
437
+
dotnet test -h|--help
438
+
```
439
+
440
+
#### Description
441
+
442
+
With Microsoft Testing Platform, `dotnet test` operates faster than with VSTest. The test-related arguments are no longer fixed, as they are tied to the registered extensions in the test project(s). Moreover, MTP supports a globbing filter when running tests. For more information, see [Microsoft.Testing.Platform](../testing/unit-testing-platform-intro.md).
443
+
444
+
> [!WARNING]
445
+
> `dotnet test` doesn't run in environments that have test projects using both VSTest and Microsoft Testing Platform in the same solution, as the two platforms are mutually incompatible.
Specifies the path to a directory that contains a project or a solution.
464
+
465
+
> [!NOTE]
466
+
> You can use only one of the following options at a time: `--project`, `--solution`, or `--directory`. These options can't be combined.
467
+
468
+
-**`--test-modules <EXPRESSION>`**
469
+
470
+
Filters test modules using file globbing in .NET. Only tests belonging to those test modules will run. For more information and examples on how to use file globbing in .NET, see [File globbing](../../../docs/core/extensions/file-globbing.md).
471
+
472
+
-**`--root-directory <ROOT_PATH>`**
473
+
474
+
Specifies the root directory of the `--test-modules` option. It can only be used with the `--test-modules` option.
475
+
476
+
-**`--list-tests`**
477
+
478
+
Lists the discovered tests instead of running the tests.
479
+
480
+
-**`--max-parallel-test-modules <NUMBER>`**
481
+
482
+
Specifies the maximum number of test modules that can run in parallel.
The [target framework moniker (TFM)](../../standard/frameworks.md) of the target framework to run tests for. The target framework must also be specified in the project file.
491
+
492
+
[!INCLUDE [os](../../../includes/cli-os.md)]
493
+
494
+
-**`-r|--runtime <RUNTIME_IDENTIFIER>`**
495
+
496
+
The target runtime to test for.
497
+
498
+
Short form `-r` available starting in .NET SDK 7.
499
+
500
+
-**`-v|--verbosity <LEVEL>`**
501
+
502
+
Sets the MSBuild verbosity level. Allowed values are `q[uiet]`, `m[inimal]`, `n[ormal]`, `d[etailed]`, and `diag[nostic]`. For more information, see <xref:Microsoft.Build.Framework.LoggerVerbosity>.
503
+
504
+
-**`--no-build`**
505
+
506
+
Specifies that the test project isn't built before being run. It also implicitly sets the `--no-restore` flag.
507
+
508
+
-**`--no-restore`**
509
+
510
+
Specifies that an implicit restore isn't executed when running the command.
511
+
512
+
-**`--no-ansi`**
513
+
514
+
Disables outputting ANSI escape characters to screen.
515
+
516
+
-**`--no-progress`**
517
+
518
+
Disables reporting progress to screen.
519
+
520
+
-**`--output <VERBOSITY_LEVEL>`**
521
+
522
+
Specifies the output verbosity when reporting tests. Valid values are `Normal` and `Detailed`. The default is `Normal`.
523
+
524
+
-**`--property:<NAME>=<VALUE>`**
525
+
526
+
Sets one or more MSBuild properties. Specify multiple properties by repeating the option:
The short form `-p` can be used for `--property`. The same applies for `/property:property=value` and its short form is `/p`.
533
+
More informatiom about the available arguments can be found in [the dotnet msbuild documentation](dotnet-msbuild.md).
534
+
535
+
-**`-h|--help`**
536
+
537
+
Prints out a description of how to use the command. The options are dynamic and might differ from one test application to another, as they are based on the registered extensions in the test project.
538
+
539
+
-**`args`**
540
+
541
+
Specifies extra arguments to pass to the test application(s). Use a space to separate multiple arguments. For more information and examples on what to pass, see [Microsoft Testing Platform](../../../docs/core/testing/unit-testing-platform-intro.md) and [Microsoft.Testing.Platform extensions](../../../docs/core/testing/unit-testing-platform-extensions.md).
542
+
543
+
> [!NOTE]
544
+
> To enable trace logging to a file, use the environment variable `DOTNET_CLI_TEST_TRACEFILE` to provide the path to the trace file.
545
+
546
+
#### Examples
547
+
548
+
- Run the tests in the project in the current directory:
549
+
550
+
```dotnetcli
551
+
dotnet test
552
+
```
553
+
554
+
- Run the tests in the `TestProject` project:
555
+
556
+
```dotnetcli
557
+
dotnet test --project ./TestProject/TestProject.csproj
558
+
```
559
+
560
+
- Run the tests in the `TestProjects` solution:
561
+
562
+
```dotnetcli
563
+
dotnet test --solution ./TestProjects/TestProjects.sln
564
+
```
565
+
566
+
- Run the tests in the `TestProjects` directory:
567
+
568
+
```dotnetcli
569
+
dotnet test --directory ./TestProjects
570
+
```
571
+
572
+
- Run the tests using `TestProject.dll` assembly:
573
+
574
+
```dotnetcli
575
+
dotnet test --test-modules "**/bin/**/Debug/net10.0/TestProject.dll"
576
+
```
577
+
578
+
- Run the tests using `TestProject.dll` assembly with the root directory:
579
+
580
+
```dotnetcli
581
+
dotnet test --test-modules "**/bin/**/Debug/net10.0/TestProject.dll" --root-directory "c:\code"
582
+
```
583
+
584
+
- Run the tests in the current directory with code coverage:
585
+
586
+
```dotnetcli
587
+
dotnet test --coverage
588
+
```
589
+
590
+
- Run the tests in the `TestProject` project, providing the `-bl` (binary log) argument to `msbuild`:
591
+
592
+
```dotnetcli
593
+
dotnet test --project ./TestProject/TestProject.csproj -bl
594
+
```
595
+
596
+
- Run the tests in the `TestProject` project, setting the MSBuild `DefineConstants` property to `DEV`:
597
+
598
+
```dotnetcli
599
+
dotnet test --project ./TestProject/TestProject.csproj -p:DefineConstants="DEV"
600
+
```
601
+
602
+
#### See also
603
+
604
+
-[Frameworks and Targets](../../standard/frameworks.md)
0 commit comments