Skip to content
Latchkey

dotnet test --filter: Select Which Tests Run

dotnet test --filter runs only the tests whose name, trait, or category match the given expression.

Filters let CI split a large suite into shards or skip slow categories. The syntax differs slightly across xUnit, NUnit, and MSTest.

What it does

dotnet test --filter passes an expression to the test platform that selects tests by properties such as FullyQualifiedName, Name, Category/TestCategory, Trait, or Priority. Expressions combine with & (and), | (or), and operators =, !=, ~ (contains).

Common usage

Terminal
dotnet test --filter "FullyQualifiedName~Integration"
dotnet test --filter "Category=Smoke"
dotnet test --filter "TestCategory!=Slow"
dotnet test --filter "Name~Login&Priority=1"

Options

Expression tokenWhat it does
FullyQualifiedName~XTests whose full name contains X
Name=XTests whose name equals X exactly
Category=X / TestCategory=XxUnit trait / NUnit-MSTest category equals X
Trait=XMatch a trait value
& | !=Combine and negate sub-expressions
~Contains operator

In CI

Use filters to shard a suite across parallel jobs (e.g. FullyQualifiedName~Group1 per job) or to run a fast smoke set on every push and the full suite nightly. Remember the property name is framework-specific: xUnit uses Category traits, NUnit and MSTest use TestCategory. Quote the whole expression so the shell does not eat the &.

Common errors in CI

"No test matches the given testcase filter" means the expression selected nothing; usually a wrong property name (Category vs TestCategory) or a typo. This exits non-zero, so an over-tight filter fails the job. An unquoted & in the filter gets interpreted by the shell as a background operator and truncates the expression.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →