Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running unit tests and integration tests separately using MSTest

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?

like image 427
Tom Robinson Avatar asked Nov 09 '11 16:11

Tom Robinson


People also ask

How unit testing and integration testing is performed?

Unit Testing is a kind of white box testing, whereas Integration Testing is a kind of black-box testing. For Unit Testing, accessibility of code is required, as it tests the written code, while for Integration Testing, access to code is not required, since it tests the interactions and interfaces between modules.

Is MSTest a unit testing framework?

The MSTest framework supports unit testing in Visual Studio. Use the classes and members in the Microsoft. VisualStudio.

What is the prerequisite to unit testing C# with MSTest and net?

Create the test project The test project requires other packages to create and run unit tests. dotnet new in the previous step added the MSTest SDK, the MSTest test framework, the MSTest runner, and coverlet for code coverage reporting. You can see the entire file in the samples repository on GitHub.


1 Answers

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.

like image 176
Peter Ritchie Avatar answered Nov 16 '22 04:11

Peter Ritchie