
This topic applies to: ✓ .NET Core SDK 1.x ✓ .NET Core SDK 2.x
Name
dotnet test - .NET test driver used to execute unit tests.
Synopsis



.NET Core 2.x


.NET Core 1.x



dotnet test [&lt;PROJECT&gt;] [-a|--test-adapter-path] [-c|--configuration] [--collect] [-d|--diag] [-f|--framework] [--filter] [-l|--logger] [--no-build] [--no-restore] [-o|--output] [-r|--results-directory] [-s|--settings] [-t|--list-tests] [-v|--verbosity]
dotnet test [-h|--help]


dotnet test [&lt;PROJECT&gt;] [-a|--test-adapter-path] [-c|--configuration] [-d|--diag] [-f|--framework] [--filter] [-l|--logger] [--no-build] [-o|--output] [-s|--settings] [-t|--list-tests]  [-v|--verbosity]
dotnet test [-h|--help]


Description
The dotnet test command is used to execute unit tests in a given project. Unit tests are console application projects that have dependencies on the unit test framework (for example, MSTest, NUnit, or xUnit) and the dotnet test runner for the unit testing framework. These are packaged as NuGet packages and are restored as ordinary dependencies for the project.
Test projects also must specify the test runner. This is specified using an ordinary &lt;PackageReference&gt; element, as seen in the following sample project file:
&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;

  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;netcoreapp1.1&lt;/TargetFramework&gt;
  &lt;/PropertyGroup&gt;

  &lt;ItemGroup&gt;
    &lt;PackageReference Include=&quot;Microsoft.NET.Test.Sdk&quot; Version=&quot;15.0.0&quot; /&gt;
    &lt;PackageReference Include=&quot;xunit&quot; Version=&quot;2.2.0&quot; /&gt;
    &lt;PackageReference Include=&quot;xunit.runner.visualstudio&quot; Version=&quot;2.2.0&quot; /&gt;
  &lt;/ItemGroup&gt;

&lt;/Project&gt;
Arguments
PROJECT
Specifies a path to the test project. If omitted, it defaults to current directory.
Options



.NET Core 2.x


.NET Core 1.x



-a|--test-adapter-path &lt;PATH_TO_ADAPTER&gt;
Use the custom test adapters from the specified path in the test run.
-c|--configuration {Debug|Release}
Defines the build configuration. The default value is Debug, but your project&#39;s configuration could override this default SDK setting.
--collect &lt;DATA_COLLECTOR_FRIENDLY_NAME&gt;
Enables data collector for the test run. For more information, see Monitor and analyze test run.
-d|--diag &lt;PATH_TO_DIAGNOSTICS_FILE&gt;
Enables diagnostic mode for the test platform and write diagnostic messages to the specified file.
-f|--framework &lt;FRAMEWORK&gt;
Looks for test binaries for a specific framework.
--filter &lt;EXPRESSION&gt;
Filters out tests in the current project using the given expression. For more information, see the Filter option details section. For additional information and examples on how to use selective unit test filtering, see Running selective unit tests.
-h|--help
Prints out a short help for the command.
-l|--logger &lt;LoggerUri/FriendlyName&gt;
Specifies a logger for test results.
--no-build
Does not build the test project prior to running it.
--no-restore
Doesn&#39;t perform an implicit restore when running the command.
-o|--output &lt;OUTPUT_DIRECTORY&gt;
Directory in which to find the binaries to run.
-r|--results-directory &lt;PATH&gt;
The directory where the test results are going to be placed. The specified directory will be created if it doesn&#39;t exist.
-s|--settings &lt;SETTINGS_FILE&gt;
Settings to use when running tests.
-t|--list-tests
List all of the discovered tests in the current project.
-v|--verbosity &lt;LEVEL&gt;
Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].


-a|--test-adapter-path &lt;PATH_TO_ADAPTER&gt;
Use the custom test adapters from the specified path in the test run.
-c|--configuration {Debug|Release}
Defines the build configuration. The default value is Debug, but your project&#39;s configuration could override this default SDK setting.
-d|--diag &lt;PATH_TO_DIAGNOSTICS_FILE&gt;
Enables diagnostic mode for the test platform and write diagnostic messages to the specified file.
-f|--framework &lt;FRAMEWORK&gt;
Looks for test binaries for a specific framework.
--filter &lt;EXPRESSION&gt;
Filters out tests in the current project using the given expression. For more information, see the Filter option details section. For additional information and examples on how to use selective unit test filtering, see Running selective unit tests.
-h|--help
Prints out a short help for the command.
-l|--logger &lt;LoggerUri/FriendlyName&gt;
Specifies a logger for test results.
--no-build
Does not build the test project prior to running it.
-o|--output &lt;OUTPUT_DIRECTORY&gt;
Directory in which to find the binaries to run.
-s|--settings &lt;SETTINGS_FILE&gt;
Settings to use when running tests.
-t|--list-tests
List all of the discovered tests in the current project.
-v|--verbosity &lt;LEVEL&gt;
Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].


Examples
Run the tests in the project in the current directory:
dotnet test
Run the tests in the test1 project:
dotnet test ~/projects/test1/test1.csproj
Filter option details
--filter &lt;EXPRESSION&gt;
&lt;Expression&gt; has the format &lt;property&gt;&lt;operator&gt;&lt;value&gt;[|&amp;&lt;Expression&gt;].
&lt;property&gt; is an attribute of the Test Case. The following are the properties supported by popular unit test frameworks:



Test Framework
Supported properties




MSTest
FullyQualifiedNameNameClassNamePriorityTestCategory


Xunit
FullyQualifiedNameDisplayNameTraits



The &lt;operator&gt; describes the relationship between the property and the value:



Operator
Function




=
Exact match


!=
Not exact match


~
Contains



&lt;value&gt; is a string. All the lookups are case insensitive.
An expression without an &lt;operator&gt; is automatically considered as a contains on FullyQualifiedName property (for example, dotnet test --filter xyz is same as dotnet test --filter FullyQualifiedName~xyz).
Expressions can be joined with conditional operators:



Operator
Function




&#124;
OR


&amp;
AND



You can enclose expressions in parenthesis when using conditional operators (for example, (Name~TestMethod1) | (Name~TestMethod2)).
For additional information and examples on how to use selective unit test filtering, see Running selective unit tests.
See also
 Frameworks and Targets .NET Core Runtime IDentifier (RID) catalog
