Search code examples
testingvisual-studio-2012vstesthost

Visual Studio 2012 vstest: run tests that do not belong to a category


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.


Solution

  • 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.