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
In the csproj
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.3.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>
command line
dotnet xunit -trait "Color=Blue"