- Article
- 12 minutes to read
This article applies to:✔️ .NET Core 3.1 SDK and later versions
Name
test dotnet
- .NET test controller to run unit tests.
resume
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
description
Dietest dotnet
The command is used to run unit tests on a specific solution. thetest dotnet
The 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.Sdk
is the test host,xeinheit
is the testing framework. Yxunit.runner.visualstudio
is 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-restore
Possibility.
Diedotnet recovery
The 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.
Workload-Manifest-Downloads
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.
argument
PROJECT | SOLUTION | DIRECTORY | DLL | EXE
- 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 using
DIRECTORY
Argument to specify the current directory.
options
caveat
Major Changes to Options:
- Since .NET 7: change
-a
to the pseudonym--The book
instead of--test-path-adapter
- Since .NET 7: change
-r
to the pseudonym--Duration
instead of--result directory
--test-adapter-path <ADAPTER_PATH>
Path to a directory to search for more test adapters. Just.dllfiles with extension
.TestAdapter.dll
they are inspected. If not specified, the test directory.dllWantedshort form
-a
Available 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 one
win-x64
machine specification--arch x86
configure the RIDwin-x86
. If you use this option, do not use the-r|--runtime
Possibility. Available since .NET 6 Preview 7.
--to blame
(Video) Intro To The .NET CLI - How To Use It, Why We Need It, And MoreRun 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 in
TestResults/<Guid>/<Guid>_Sequence.xml
which 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
.See AlsoGDPP FAQ - Partner CenterMaintenance notifications - Azure Virtual MachinesOverview of Azure network servicesOutlook performance issues on an OST or PST file in Cached Exchange Mode - OutlookTo capture a memory dump from a native application running on .NET 5.0 or later, you can force the use of Procdump by setting the
VSTEST_DUMP_FORCEPROCDUMP
environment 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 are
completely
(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 be
completely
,Mini
, oneither
. Whenneither
is 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 Windows
netcoreapp2.1
and later on Linux withnetcoreapp3.1
and higher and on macOS withred5.0
or after. implicit--to blame
y--fault-hang
.
-c|--configuration <CONFIGURATION>
Defines the build configuration. The default for most projects is
debugging
, 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 projectsTo 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>.txt
for test host registration and*.datacollector_<Dato>.txt
for 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,
detail
instead 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 only
would becomeverbosity=detallado; consoleLoggerParameters=ErrorsOnly
.- Use the full name of the switch, not the abbreviated form (for example,
--no-build
Do not build the test project before running it. It also implicitly sets the
--no-restore
Bandera.--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 frames
property), you must also define it--Marco
if you specify this option.test dotnet
always 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 one
win-x64
machine specification--os Linux
configure the RIDlinux-x64
. If you use this option, do not use the-r|--runtime
Possibility. 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 is
Test results
in the directory containing the project file.short form
-r
Available in versions of the .NET SDK earlier than 7.-r|--runtime <RUNTIME_IDENTIFIER>
The target runtime to test.
short form
-r
available since .NET SDK 7.-s|--settings <SETTINGS_FILE>
Die
.runsettings
File to use to run the tests. theobjective platform
Element (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:- Configure unit tests using a .runsettings file.
- Set up a test run
-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 are
quiet]
,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 to
msbuild
. In this case, you can find the available arguments inthe dotnet msbuild documentation. - If you specify a.dllo one.exe, the call is diverted
counterproof
. In this case, you can find the available arguments indotnet vstest documentation.
- If you specify a project, solution, or directory, or omit this argument, the call is routed to
run setup
argument
Onlinerun setup
they are passed as the last arguments on the command line after "--" (note the space after --). Onlinerun setup
they 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.
examples
Run the tests on the project in the current directory:
test dotnet
Run the tests on the
exam 1
Project:dotnet-Test ~/projects/test1/test1.csproj
Run the tests with
test1.dll
Mounting: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 the
exam 1
project, providing the-Degree in Law
(binary protocol) argument tomsbuild
:test dotnet ~/projects/test1/test1.csproj -bl
Run the tests on the
exam 1
project running MSBuilddefine constants
property 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 framework | supported properties |
---|---|
MS test |
|
xEinheit |
|
It is not like this? |
|
Die<Operator>
describes the relationship between property and value:
Operator | function |
---|---|
= | exact match |
!= | not an exact match |
~ | Contains |
!~ | Not included |
<Wert>
is a string. All searches are not case sensitive.
an expression without<Operator>
is automatically consideredcontains
andFully Qualified Name
property (eg.test dotnet --xyz filter
its the same asdotnet test --filter Fully Qualified Name~xyz
).
Expressions can be combined with conditional operators:
Operator | function |
---|---|
| | O |
& | Y |
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.
See also
- framework conditions and goals
- .NET Runtime Identifier (RID) - Catalog
- Pass runsettings arguments from the command line