16

Is it possible to run all tests that do not belong to a category from the command line? From the documentation, I know that I can run all tests that are a member of a category doing something like:

vstest.console.exe myTestProject.dll /TestCaseFilter:TestCategory="Nightly"

What I want to do is assign a few test methods to a test category and then run those tests in one run. I then want to run the remainder of the tests in a separate test run (which is where my current problem lies). I have over 1000 tests, so I am hoping that I don't have to do a search and replace on all the TestMethod attributes to add a 'basic' category. I also don't want to have to separate the tests out into different projects.

Thanks.

acarlon
  • 16,764
  • 7
  • 75
  • 94

1 Answers1

25

Well, I got the tumbleweed badge for this question, so I guess nobody is interested. In case someone does stumble onto the same problem, I found that I could just use the != operator. The Microsoft documentation is very lean, but I found the info I needed in MSDN blog "Running selective unit tests in VS 2012 RC using TestCaseFilter".

So, the answer is:

vstest.console.exe myTestProject.dll /TestCaseFilter:TestCategory!="Nightly"

Update: As pointed out by Rob Bos below. The docs now have:

dotnet test --filter FullyQualifiedName!=MSTestNamespace.UnitTestClass1.TestMethod1

Runs all tests except MSTestNamespace.UnitTestClass1.TestMethod1

Source Running selective unit tests on MSDN.

acarlon
  • 16,764
  • 7
  • 75
  • 94
  • 6
    I agree that there's not enough documentation on this. If you have multiple TestCategories, you can filter on multiple expressions: `"TestCategory!=Other&TestCategory!=Another&TestCategory!=That"` – Carl Walsh Mar 24 '15 at 04:40
  • Thank you for the solution! :) This is still missing in the documentation. – arkod Sep 12 '16 at 10:42
  • 1
    The docs have been improved! This works in VsTest as well: [https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests](https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests) – Rob Bos Apr 04 '18 at 14:13