ediblecode
ediblecode

Reputation: 11971

How to split unit tests into groups

I am using Visual Studio 2008 and I would like to be able to split up my unit tests into two groups:

  1. Quick tests
  2. Longer tests (i.e. interactions with database)

I can only see an option to run all or one, and also to run all of the tests in a unit test class.

Is there any way I can split these up or specify which tests to run when I want to run a quick test?

Thanks

Upvotes: 3

Views: 5662

Answers (3)

Mark Hurd
Mark Hurd

Reputation: 10931

There is the Test List Editor. I'm not at my Visual Studio computer now so I'll just point to this answer.

Upvotes: 1

Stealth Rabbi
Stealth Rabbi

Reputation: 10346

I would distinguish your unit test groups as follows:

  1. Unit Tests - Testing single methods / classes, with stubbed dependenices. Should be very quick to execute, as there are only internal dependencies.
  2. Integration Tests - Testing two or more components together, such as your Data Access classes with an actual backed database. These are generally lengthy, as you may be dealing with an external dependency such as a DB or web service. However, these could still be quick tests depending on what components you are integrating. The key here is the scope of the test is different than Unit Tests.

I would create seperate test libraries, i.e. MyProj.UniTests.dll and MyProj.IntegrationTests.dll. This way, your Unit Tests library would have fewer dependenices than your Integration tests. It will then be easy to specify which test group you want to run.

You can set up a continuous integration server, if you are using something like that, to run the tests at different times, knowing that group 1 is quicker than the second. For example, Unit Tests could run immediatley after code is checked in to your repository, and Integration Tests could run overnight. It's easy to set something like this up using Team City

Upvotes: 7

Rich Tebb
Rich Tebb

Reputation: 7126

If you're using NUnit, you could use the CategoryAttribute.

The equivalent in MSTest is the TestCategory attribute - see here for a description of how to use it.

Upvotes: 10

Related Questions