views:

100

answers:

3

Can you group unit tests within a single testproject in VS2008?

For instance - test1 and test2 belongs to group A. Test4 and test5 belongs to group B.

I don't want the tests in group B to run unless I explicitly select them. This is because not all tests are supposed to be included in the automatic testing.

EDIT :
Rephrasing second part.
I can create groups by using the test list editor. Is it possible to select only one or two of these groups to be set up for automatic testing?

E.g. I want group A to run as automated tests every night and group B is for manual test runs.

A: 

The concept behind Visual Studio Unit Test strongly recommends to use a single Test Project for each target assembly. Sure, it is possible to use a single Test Project for all Unit Tests, but you have to write them manually. The Unit Tests wizard is not that flexible.

NUnit is more flexible. There is no restriction in which assembly you store your Unit Test. You can use a single assembly for all Unit Tests or even store the in the same class as the target class you want to test.

Alexander
+3  A: 

In the test view window there is a 'Group By' combobox. You can group tests on class name, namespace, description etc.

So by using that in combination with some attributes which are available on your test methods, such as Category you can be more selective when running tests.

EDIT: this is only a solution when manually running the tests. Maybe a similar solution is availble with automatic testing, where you choose to run only tests of a certain Category or in a certain namespace.

Gerrie Schenck
This solves the grouping, and I suppose I can create custom attributes to suit my own needs.Is it possible to select one (or more) of the created groups for automated testing?
John
This will work with automated testing as well, and in fact this is a preferred method for long running tests (excluded them from most builds except for the once/twice a day scheduled builds).
SnOrfus
+2  A: 

Check out the Test List Editor (under Test | Windows). This shows you all tests in a Solution. At the left you can create a TreeView of groups and each test can be dragged into a group. With checkboxes on each TreeView node you easily toggle which (group(s) of) test(s) you want to run or debug.

Is this what you were looking for?

This information seems to be stored in the vsmdi metadata file, so it should be persisted. However, I am not sure if (and how) this ties in with automatic testing. It looks like a VS GUI feature to me, meant for manual grouping and running of tests.

EDIT: For automated testing I would try to separate test code for different "occasions" (like eg. quick unit tests you always want to run when working on code, performance tests that could take a bit of time, integration tests over multiple layers, etc.) into different test projects semantically, even though you're using the same unit test framework to physically implement all these tests. Then you should be able to select the correct group of tests to be run at the right time (check in, daily build, manual test when needed).

peSHIr