Search code examples
c#visual-studiounit-testingvisual-studio-2012mstest

How to exclude certain tests in the Visual Studio Test Runner?


I have attributes on certain tests that I ideally don't want to run on every build. Most of my tests are normal unit tests and I do want them to run on every build.

So: how can I exclude a test by category or project type?

For example, I'd like to exclude CodedUItests:

[CodedUITest]
public class SearchViewTests

...or exclude tests in a given TestCategory:

[TestMethod]
[TestCategory("Database Integration")]
public void ContactRepositoryGetByIdWithIdExpectCorrectContact()

I particularly want to exclude the coded UI tests as they disrupt my ability to continue working, whereas all the other tests will happily run in the background without disturbing me.

Originally this question was about Visual Studio 2012, so I'd prefer solutions that work in that version and higher.


Solution

  • The only "solution" (or better workaround) I found to work is to specify a "FullName" filter. Basically I usually structure my solution like

    • ProjectA
    • ProjectA.UnitTests
    • ProjectA.IntegrationTests

    and so on. Now I can specify a filter in the Test Explorer like FullName: "UnitTests" which seems to work.
    (I'd expected to be able to use a regex within the search name but it doesn't seem to be supported.)

    enter image description here