How do you filter xunit tests by trait with “dotnet test”?

I found the answer (only tests attributed [Trait("TraitName", "TraitValue")] are executed):

dotnet test --filter TraitName=TraitValue

Alternatively, you can filter by not having a trait value (tests attributed [Trait("TraitName", "TraitValue")] are execluded from run)

dotnet test --filter TraitName!=TraitValue

In my example above, this means I can run:

dotnet test --filter Color=Blue

More docs here: https://github.com/Microsoft/vstest-docs/blob/master/docs/filter.md

Leave a Comment