dotnet test command - .NET CLI (2023)

  • Article
  • 12 minutes to read

This article applies to:✔️ .NET Core 3.1 SDK and later versions


test dotnet- .NET test controller to run unit tests.


dotnet-Prueba [<PROYECTO> | <LOSUNG> | <VERZEICHNIS> | <DLL> | <EXE>] [--test-adapter-path <ADAPTER_PATH>] [-a|--arch <ARCHITEKTUR>] [--blame] [--blame-crash] [--blame-crash-dump-type < DUMP_TYPE>] [--blame-crash-collect-always] [--blame-hang] [--blame-hang-dump-type <DUMP_TYPE>] [--blame-hang-timeout <TIMESPAN>] [-c |--configuration <CONFIGURACIÓN>] [--recopilar <DATA_COLLECTOR_NAME>] [-d|--diag <LOG_FILE>] [-f|--framework <FRAMEWORK>] [-e|--environment <NAME="VALUE ">] [--filter <EXPRESIÓN>] [--interactive] [-l|--logger <LOGGER>] [--no-build] [--nologo] [--no-restore] [-o| --output <DIRECTORIO_SALIDA>] [--os <SO>] [--results-directory <RESULTS_DIR>] [-r|--runtime <RUNTIME_IDENTIFIER>] [-s|--settings <SETTINGS_DATEI>] [-t |--list-tests] [-v|--ausführlichkeit <LEVEL>] [<args>...] [[--] <RunSettings arguments>]dotnet test -h|--help


Dietest dotnetThe command is used to run unit tests on a specific solution. thetest dotnetThe command creates the solution and runs a test host application for each test project in the solution. The test host runs tests against the specified project using a test framework, for example: MSTest, NUnit, or xUnit, and reports the success or failure of each test. If all tests succeed, the test runner returns 0 as the exit code; Otherwise, 1 is returned if a test fails.

For multi-goal projects, tests are performed for each goal framework. The test host and unit test framework are packaged as NuGet packages and restored as ordinary dependencies for the project.

Test projects specify the test runner with an ordinary one<Package reference>as seen in the following sample project file:

<Proyecto Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4. 1".

Where fromMicrosoft.NET.Test.Sdkis the test host,xeinheitis the testing framework. Yxunit.runner.visualstudiois a test adapter that allows the xUnit framework to work with the test host.

implicit recovery

you don't have to rundotnet recoverybecause it is implicitly executed by any command that requires recovery, likedotnet neu,dotnet-Build,run dotnet,test dotnet,publish dotnet, ydotnet package. To disable implicit restore, use the--no-restorePossibility.

Diedotnet recoveryThe command is still useful in certain scenarios where an explicit restore makes sense, e.g.Continuous integration is built into Azure DevOps Servicesor on build systems that need to explicitly control when recovery occurs.

For information on managing NuGet feeds, seeDotnet recovery documentation.


When you run this command, it initiates an asynchronous download of workload advertising manifests in the background. If the download is still in progress after completing this command, the download will stop. For more information, seepromotional manifestos.



    • Path to test project.
    • way to solution.
    • Path to a directory containing a project or solution.
    • Path to a test project.dllArchive.
    • Path to a test project.exeArchive.

    If not specified, the effect is the same as when usingDIRECTORYArgument to specify the current directory.



Major Changes to Options:

  • Since .NET 7: change-ato the pseudonym--The bookinstead of--test-path-adapter
  • Since .NET 7: change-rto the pseudonym--Durationinstead of--result directory
  • --test-adapter-path <ADAPTER_PATH>

    Path to a directory to search for more test adapters. Just.dllfiles with extension.TestAdapter.dllthey are inspected. If not specified, the test directory.dllWanted

    short form-aAvailable in versions of the .NET SDK earlier than 7.

  • --arch <ARQUITECTURA>

    Specifies the target architecture. This is a shorthand syntax for specifyingRuntime Identifier (RID), where the supplied value is combined with the default RID. for example in onewin-x64machine specification--arch x86configure the RIDwin-x86. If you use this option, do not use the-r|--runtimePossibility. Available since .NET 6 Preview 7.

  • --to blame

    (Video) Intro To The .NET CLI - How To Use It, Why We Need It, And More

    Run the tests in Fault mode. This option is useful for isolating problematic tests that cause the test host to crash. When a crash is detected, it creates a stream file inTestResults/<Guid>/<Guid>_Sequence.xmlwhich captures the order of the tests that were executed before the crash.

    This option does not create a memory dump and is not useful if the test crashes.

  • --guilt shock(Available since the .NET 5.0 SDK)

    Runs tests in fault mode and captures a memory dump if the test host shuts down unexpectedly. This option depends on the version of .NET used, the nature of the error, and the operating system.

    Exceptions in managed code are automatically dumped in .NET 5.0 and later. A dump is generated for testhost or any child process that was also running in .NET 5.0 and crashed. Crashes in native code do not produce a dump. This option works on Windows, macOS, and Linux.

    Memory dumps in native code or when using .NET Core 3.1 or earlier can be captured using Procdump on Windows only. A directory containingprocdump.exeyprocdump64.exeit must be in the PATH or PROCDUMP_PATH environment variable.Download the tools. implicit--to blame.

    To capture a memory dump from a native application running on .NET 5.0 or later, you can force the use of Procdump by setting theVSTEST_DUMP_FORCEPROCDUMPenvironment variable too1.

  • --blame-crash-dump-tipo <DUMP_TYPE>(Available since the .NET 5.0 SDK)

    The type of memory dump to collect. Supported dump types arecompletely(Default) andMini. implicit--guilt shock.

  • --blame-crash-collect-immer(Available since the .NET 5.0 SDK)

    Captures a memory dump on the expected and unexpected exits from the test host.

  • --fault-hang(Available since the .NET 5.0 SDK)

    Run tests in blame mode and capture a crash dump when a test times out.

  • --blame-hang-dump-type <DUMP_TYPE>(Available since the .NET 5.0 SDK)

    The type of memory dump to collect. Should becompletely,Mini, oneither. Whenneitheris specified, the test host expires but no dump is performed. implicit--fault-hang.

  • --blame-hang-timeout <TIMESPAN>(Available since the .NET 5.0 SDK)

    Timeout per test, after which a dump is triggered and the test host process and all its child processes are dumped and terminated. The timeout value is specified in one of the following formats:

    • 1.5 standard, 1.5 standard, 1.5 standard
    • 90 minutes, 90 minutes, 90 minutes, 90 minutes
    • 5400, 5400, 5400, 5400
    • 5400000ms, 5400000mil, 5400000ms, 5400000ms

    If no unit is used (for example, 5400000), the value is assumed to be in milliseconds. When used in conjunction with data-driven tests, the timeout behavior depends on the test adapter used. For xUnit, NUnit. and MSTest 2.2.4+, the timeout is renewed after each test case. For MSTest before version 2.2.4, the timeout is used for all test cases. This option is also compatible with Windowsnetcoreapp2.1and later on Linux withnetcoreapp3.1and higher and on macOS withred5.0or after. implicit--to blamey--fault-hang.

  • -c|--configuration <CONFIGURATION>

    Defines the build configuration. The default for most projects isdebugging, but you can override the build configuration settings in your project.

  • --recolectar <DATA_COLLECTOR_NAME>

    Activates the data collector for the test run. For more information, seeMonitor and analyze test execution.

    For example, you can collect code coverage using the--collect "Codeabdeckung"Possibility. For more information, seeUse code coverageyCustomize code coverage analysis.

    (Video) Dotnet CLI - Build, Test and Publish projects

    To collect code coverage, you can also useMeet Nordicausing the--collect "XPlat Code Coverage"Possibility.

  • -d|--diag <LOG FILE>

    Activates diagnostic mode for the test platform and writes diagnostic messages to the specified file and files next to it. The process that logs the messages determines which files are created, e.g.*.host_<Dato>.txtfor test host registration and*.datacollector_<Dato>.txtfor data collector registration.

  • -e|--environment <NAME="VALUE">

    Sets the value of an environment variable. Creates the variable if it doesn't exist and overwrites it if it does. Using this option forces tests to run in an isolated process. The option can be specified multiple times to provide multiple variables.

  • -f|--framework <MARCO>

    DieTarget Framework Nickname (TFM)the target framework to test against. The target framework must also be specified in the project file.

  • --filter <EXPRESSION>

    Filters the tests in the current project based on the specified expression. Only tests that match the filter expression are executed. For more information, seeDetails about filter optionsSection. For more information and examples of how to use selective unit test filtering, seeRun selective unit tests.

  • -?|-h|--help

    Prints a description of how to use the command.

  • - interactive

    Allows the command to pause and wait for user input or action. For example, to complete authentication. Available from the .NET Core 3.0 SDK.

  • -l|--logger <LOG>

    Specifies a logger for the test results and optional switches for the logger. Specify this parameter multiple times to enable multiple loggers. For more information, seereport test results,recorder switch, and theexampleslater in this article.

    To pass command line switches to the logger:

    • Use the full name of the switch, not the abbreviated form (for example,detailinstead ofv).
    • Omit all leading hyphens.
    • Replace the space between each switch with a semicolon;.
    • If the switch has a value, replace the colon separator between that switch and its value with the equal sign=.

    For example,-v: verbose --consoleLoggerParameters: errors onlywould becomeverbosity=detallado; consoleLoggerParameters=ErrorsOnly.

  • --no-build

    Do not build the test project before running it. It also implicitly sets the--no-restoreBandera.

  • --nolog

    Run tests without displaying the Microsoft TestPlatform banner. Available from the .NET Core 3.0 SDK.

  • --no-restore

    Does not perform an implicit restore when running the command.

    (Video) Run NUnit tests from command line: NUnit Console and Dotnet test

  • -o|--Output <OUTPUT_DIR>

    Directory in which to find the binaries to run. If not specified, the default path is./bin/<config>/<framework>/. For projects with multiple target frameworks (through thetarget framesproperty), you must also define it--Marcoif you specify this option.test dotnetalways run tests from the output directory. You can useApplication domain.Home directoryto consume test assets in the output directory.

  • --os <operating system>

    Specifies the target operating system (OS). This is a shorthand syntax for specifyingRuntime Identifier (RID), where the supplied value is combined with the default RID. for example in onewin-x64machine specification--os Linuxconfigure the RIDlinux-x64. If you use this option, do not use the-r|--runtimePossibility. Available since .NET 6.

  • --results-directory <RESULTS_DIR>

    The directory where the test results will be placed. If the specified directory does not exist, it will be created. The default isTest resultsin the directory containing the project file.

    short form-rAvailable in versions of the .NET SDK earlier than 7.

  • -r|--runtime <RUNTIME_IDENTIFIER>

    The target runtime to test.

    short form-ravailable since .NET SDK 7.

  • -s|--settings <SETTINGS_FILE>

    Die.runsettingsFile to use to run the tests. theobjective platformElement (x86|x64) has no effect ontest dotnet. To run tests that target x86, install the x86 version of .NET Core. The bitness ofdotnet.exethat is in the path is used to run tests. For more information, see the following resources:

  • -t|--test-list

    List the detected tests instead of running the tests.

  • -v|--verbosity <LEVEL>

    Sets the verbosity level of the command. The allowed values ​​arequiet],Minimum],normal],d[verbose], yTo diagnose. The default isMinimum. For more information, seeLogger verbose.

  • argument

    Specifies additional arguments to pass to the adapter. Use a space to separate multiple arguments.

    The list of possible arguments depends on the specified behavior:

    • If you specify a project, solution, or directory, or omit this argument, the call is routed tomsbuild. In this case, you can find the available arguments inthe dotnet msbuild documentation.
    • If you specify a.dllo one.exe, the call is divertedcounterproof. In this case, you can find the available arguments indotnet vstest documentation.
  • run setupargument

Onlinerun setupthey are passed as the last arguments on the command line after "--" (note the space after --). Onlinerun setupthey are given as[name]=[value]pairs A space is used to separate multiple[name]=[value]couples

Example:dotnet-Test – MSTest.DeploymentEnabled=false MSTest.MapInconclusiveToFailed=True

For more information, seePass RunSettings arguments from the command line.

(Video) You NEED this if you use the .NET CLI!


  • Run the tests on the project in the current directory:

    test dotnet
  • Run the tests on theexam 1Project:

    dotnet-Test ~/projects/test1/test1.csproj
  • Run the tests withtest1.dllMounting:

    prueba dotnet ~/projects/test1/bin/debug/test1.dll
  • Run the tests on the project in the current directory and generate a test result file in trx format:

    try dotnet --log trx
  • Run the tests on the project in the current directory and generate a code coverage file (after installingMeet NordicaIntegration of collectors):

    prueba dotnet --collect:"XPlat-Codeabdeckung"
  • Run the tests on the project in the current directory and generate a code coverage file (Windows only):

    test dotnet --collect "Code Coverage"
  • Run the tests on the project in the current directory and verbally log in to the console:

    dotnet test --logger "console;verbosity=verbose"
  • Run the tests on the project in the current directory and log in with the trx loggertest results.trxin themTest resultsMaps:

    dotnet test --logger "trx;log file name=test results.trx"

    Since the log file name is specified, in the case of a multi-target project, the same name is used for each target framework. The result of each target frame overrides the result of previous target frames. The file is created inTest resultsFolder in the test project folder because relative paths are relative to that folder. The following example shows how to create a separate file for each target platform.

  • Run the tests on the project in the current directory and use the trx logger to log the files in theTest resultsFolders with unique file names for each target platform:

    dotnet test --log:"trx;LogFilePrefix=test results"
  • Run the tests on the project in the current directory and log in with the HTML loggertest results.htmlin themTest resultsMaps:

    test dotnet --logger "html;log file name=test results.html"
  • Run the tests on the project in the current directory and report the tests that were running when the test host failed:

    dotnet-Test – fail
  • Run the tests on theexam 1project, providing the-Degree in Law(binary protocol) argument tomsbuild:

    test dotnet ~/projects/test1/test1.csproj -bl
  • Run the tests on theexam 1project running MSBuilddefine constantsproperty toENTw:

    test dotnet ~/projects/test1/test1.csproj -p:SetConstants="DEV"

Details about filter options

--filter <EXPRESSION>

<expression>has the format<property><operator><value>[|&<expression>].

<property>is an attribute ofTest cases. The following properties are supported by popular unit testing frameworks:

test frameworksupported properties
MS test
  • Fully Qualified Name
  • Name
  • class name
  • priority
  • test category
  • Fully Qualified Name
  • display name
  • Category
It is not like this?
  • Fully Qualified Name
  • Name
  • test category
  • priority

Die<Operator>describes the relationship between property and value:

=exact match
!=not an exact match
!~Not included

<Wert>is a string. All searches are not case sensitive.

an expression without<Operator>is automatically consideredcontainsandFully Qualified Nameproperty (eg.test dotnet --xyz filterits the same asdotnet test --filter Fully Qualified Name~xyz).

Expressions can be combined with conditional operators:


You can enclose expressions in parentheses when you use conditional operators (for example,(Nombre~Testmethode1) | (Nombre~Testmethode2)).

For more information and examples of how to use selective unit test filtering, seeRun selective unit tests.

(Video) .NET CLI - build and test - code coverage and coverage report

See also


1. How to collect the code coverage of your tests in .NET
(Nick Chapsas)
2. The .NET CLI | a dense and comprehensive overview
(Amichai Mantinband)
3. Generate unit test html report using dotnet test
(Automation 100)
4. .NET CLI Complete Walkthrough
5. Using System.CommandLine to Build CLI Apps
(Muhammad Rehan Saeed)
6. Should I Know the .NET CLI? Is It Important?


Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated: 14/07/2023

Views: 6203

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.