Casper Broeren
Casper Broeren

Reputation: 780

TFS visual studio test "Test Filter criteria" and xunit Traits

I'm trying to filter out some unit test marked with the xunit trait category. On my build server I don't want unit test to run with category integration

 [Trait("Category", "Integration")]

When I don't use the 'Test Filter criteria' in TFS VS test step, the unit test all get executed. But when I apply the desired filter

Category!=Integration

It doesn't run any tests at all. I've tried all variations but no success. I also tried using the 2.* version of the test task.

Upvotes: 4

Views: 2246

Answers (2)

Ondrej Peterka
Ondrej Peterka

Reputation: 3427

Now (Februaray 2022), this is not problem anymore. However, I have had some issues getting it working and I have ended up here anyway, so just couple of points:

  • Must be in such configuration built where the test project is really built (e.g. in Release the test project is often not built)
  • Multiple detected test dlls seem to cause trouble (better to filter just really those you want)
  • The name of the trait (and the value ) can be arbitrary (16.8 and 17.0.0 at least), i.e. the text in Test Filter Criteria does NOT need anymore to be some of the vstest standard names, like TestCategory

enter image description here

Upvotes: 0

JeremyH
JeremyH

Reputation: 21

Instead of using [Trait("Category", "Integration")], use [Trait("TestCategory", "Integration")]. XUnit doesn't care what you put in for these key-value pairs, but the TFS Test runner task DOES. The Test Filter Criteria box only works with a prescribed set of attributes. I have this working for our builds. Ran into the same problem you are describing. After analyzing the build output, (and getting ALL test projects switched to XUnit - that is also a key... don't have a mix of MSTest and XUnit).

Upvotes: 2

Related Questions