Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 434
acarlon Avatar asked Nov 11 '13 06:11

acarlon


People also ask

How do I run a specific test in Visual Studio?

If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

What is the difference between MSTest and VSTest?

There is a difference between vstest and mstest - the former is a test runner and the later is a test framework.

How use MSTest command line?

Use the command MSTest from the command prompt. The MSTest command expects the name of the test as parameter to run the test. Just type MSTest /help or MSTest /? at the Visual Studio command prompt to get help and find out more about options.


1 Answers

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.

like image 182
acarlon Avatar answered Sep 22 '22 06:09

acarlon