Running unit tests and integration tests separately using MSTest

integration-testingmstestunit testingvisual studio 2010

We use Visual Studio 2010 Ultimate with tests written in MSTest. Both our unit tests and integration tests* are written in MSTest.

**By our definition, an integration test is an MSTest TestMethod that takes a while to run and/or calls out to external components such as a database or web services.*

I'm looking for a way of easily filtering out the integration tests so that only unit tests run without all the integration tests running too.

My ideas so far:

  1. Mark integration tests with the [Ignore] attribute. This works but is a real pain when you do want to run the integration tests.

  2. Assign a [TestCategory] attribute to the different test types. This allows them to be run separately but only through the Test View panel. You can't use CTRL+R, A (Run All Tests in Solution) or other similar shortcuts/hotkeys.

  3. The integration tests are in a separate project, is there something that could be done to stop them running at the project level? As long as it's easy to toggle.

  4. Write the integration tests in a different test framework, e.g. NUnit. This would keep them totally separate from a tooling point of view.

Does anyone have any other suggestions? Are there any plug-ins that can help with this?

Best Answer

I recommend having a different project (or projects) for integration tests because depending on your runner the only real way to run or not run tests across all runners is to include or not include a test class library.

But, I also recommend, if you're using MSTest, to use the TestCategoryAttribute to tag non-unit tests. You can then "filter" tests to be run in Test View with MSTest.

Runners like Resharper and apparently TestDriven.net (http://bit.ly/tmtYC2) allow you to then filter-out those tests from general unit-test executions.