How do I run specific tests using dotnet test?
Asked Answered
P

2

101

I have a large test suite in a .NET Core project. I can use the Test Explorer window to select a few tests to run.

I can also run the whole test suite on the command line with dotnet test. Is there a way to run only one (or a few) tests on the command line?

Parity answered 10/6, 2016 at 15:45 Comment(0)
B
129

With the dotnet version 1.0.0, you have to use the --filter option:

You can filter by DisplayName, FullyQualifiedName and Traits.

Ex:

dotnet test --filter "FullyQualifiedName=YourNamespace.TestClass1.Test1"

Also, these operators are allowed: =, != and ~ (contains).

More info here: docs

Boulevardier answered 14/3, 2017 at 13:42 Comment(3)
I tried this out and this solution works also for the 1.1 version and a [Theory] decorated method. Switches -method and -class aren't available in 1.1 anymore and you'll get an error: MSBUILD: error MSB1001: Unkown switch. Switch: -methodSaltzman
Yep, I just confirmed this. -method no longer works, but --filter does. Thanks @andrecarlucci!Parity
Since version 15.1 the expression can be a keyword that will be matched against the fully qualified names. As the documentation states "dotnet test --filter xyz is same as dotnet test --filter FullyQualifiedName~xyz" Which is much comfortable !Stoneware
S
9

Since this question is tagged with xUnit, the command for the dotnet xUnit CLI command is as follows:

dotnet xunit -method FullyQualifiedName
Sidewalk answered 10/8, 2017 at 19:49 Comment(1)
FYI: dotnet xunit is now retired. dotnet test is right CLI command (powered by the xunit.runner.visualstudio package).Parity

© 2022 - 2024 — McMap. All rights reserved.