Skip to main content

Dotnet Test Command

Sample Test Command

dotnet test "--logger:junit;LogFilePath=./test-reports/results.xml" ./ -v n --no-build --filter
TestCategory=xxx -- NUnit.NumberOfTestWorkers=10 -- TestRunParameters.Parameter\(name=\"BUILD_NAME\", value=\"xxx\"\) --
TestRunParameters.Parameter\(name=\"RUN_ID\", value=\"0\"\)

The ––filter option can be used to fine tune which tests are executed.

For example to run the single test Test1 in TestClass1:

dotnet test --filter DisplayName=XUnitTestProject1.TestClass1.Test1

To run all the tests in a single test class, the ~ contains operator can be used, for example:

dotnet test --filter DisplayName~XUnitTestProject1.TestClass1

To run all tests with a specific category (trait), for example all the Smoke Tests (in this would be the attribute [Trait("Category", "Smoke Test")]):

dotnet test --filter Category="Smoke Test"

The ! not operator can be used as part of the filter expression, for example to run all tests except for Test1:

dotnet test --filter FullyQualifiedName!=XUnitTestProject1.TestClass1.Test1