How to filter xunit tests by attribute using the dotnet test?

I have a .NET Core test project that uses Xunit 2.2. Some of my tests are marked with traits.

[Fact]
[Trait("Color", "Blue")]
public void TestBlue()
{
}

What is the correct command line syntax for "dotnet test" to run tests where the dash is Color == Blue?

I am using the .NET Core CLI 1.0.0-rc4 which uses csproj and not project.json.

I am trying to use dotnet test --filter $something, but no matter what I use for $ something, I see this error:

Error: [xUnit.net 00: 00: 00.7800155] E2ETests: exception filtering tests: no tests match the filter because it contains one or more invalid properties ($ something). Specify a filter expression that contains valid properties (DisplayName, FullyQualifiedName) and try again.

+6
source share
2 answers

I found the answer:

dotnet test --filter TraitName=TraitValue

In addition, you can filter without meaning a value

dotnet test --filter TraitName!=TraitValue

In my example above, this means that I can run:

dotnet test --filter Color=Blue

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

+9
source

At 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"
0
source

Source: https://habr.com/ru/post/1015012/


All Articles