Search code examples
nunitvstestvstest.console.exe

How to run all Unit Tests that DON'T have a trait?


When running tests using VSTest, the /TestCaseFilter option can be used to select tests that have a specific trait.

For example, the following selects all Unit Tests that have been marked as being slow:

/TestCaseFilter:"TestCategory=Slow"

But what if my goal isn't to select tests with specific traits, but rather to select tests that don't have any specified traits. The idea here is that regular Unit Tests would never have any traits assigned to them, and only the special tests would. For PR Builds, my goal would then be to only run the regular tests, and ignore everything else.

Is there no way to do this? I've tried the following, but they don't work:

/TestCaseFilter:"TestCategory="
/TestCaseFilter:"TestCategory=''"

I know I could do something like this, but then I'd need to remember to update it each time a new trait gets created:

/TestCaseFilter:"TestCategory!=A & TestCategory !=B & etc."

Thanks in advance!


Solution

  • This is currently impossible as a limitation of VSTest testing platform, see https://github.com/microsoft/vstest/issues/2818