Home Download Documentation Getting Started Support Other Versions


csUnit supports categorization of tests. Basically this means you can assign categories to tests and test fixtures, and then use the categorization for instance for selecting tests.

If you don't need this feature right now you can safely ignore it for now by jumping to the next topic. This is one of the design principles we try to follow wherever possible.

If you assign one or more category to a test or a test fixture, please be aware of the following rules:

  1. If a test has no categories assigned then the default setup/teardown method will be executed. The default setup/teardown method is the one that has no categories assigned to it. If no such default setup/teardown method exists, no setup/teardown will get executed.
  2. If a test has one or more categories assigned then the setup/teardown for that category or those categories will be executed. If a categorized setup/teardown method doesn't exists, the default method will be executed if it exists.
  3. If more than one default setup/teardown method exists, or if more than one categorized setup/teardown method for the same category exists, this is considered to be an error and the test(s) will fail. This test is performed per test fixture. The latter means that in a hierarchy of test fixtures a base class can have a setup/teardown method, and a derived class can have a setup/teardown method, either default or categorized.
  4. If a test fixture is derived from a base class that is itself a test fixture, setup/teardown methods from the base class will not be considered for the derived test fixture. Also, even if a method in the base class is declared virtual and marked as SetUp/TearDown, it will not be considered by csUnit's runtime. If you need to execute setup/teardown code in the base class, you need to call the base class method from your code, e.g. base.MySpecialSetupMethod().

Once you have defined categories for your tests you can then select categories in the graphical user interface. When you then save your settings as a recipe, the category selection will be save along with it. After that you can supply the recipe to csUnitCmd, e.g. for inclusion in your automated build. The category selector is part of csUnit's runtime environment regardless of the front end.

Category Hierarchy

Both TestFixture and Test support categories. As the Test methods are always contained in a TestFixture, and as both can be assigned to one or more categories, there are more scenarios to be explored.

Let's take the following two test fixtures:

   [Fixture(Categories = "DB")]
   public class Fixture10 {
      [Test(Categories = "mySQL")]
      public void Test1() {

      [Test(Categories = "MSFT")]
      public void Test2() {

   [Fixture(Categories = "DATA")]
   public class Fixture2 {
      [Test(Categories = "mySQL")]
      public void Test3() {

      [Test(Categories = "MSFT")]
      public void Test4() {

      [Test(Categories = "Oracle")]
      public void Test5() {

There are now several scenarios possible, and depending on which categories you include or exclude, a different set of tests will be executed.

Included Categories Excluded Categories Executed Tests
DB - Test1, Test2
DATA - Test3, Test4, Test5
DB mySQL Test2
DATA MSFT Test3, Test5
DATA mySQL, Oracle Test4
- MSFT Test1, Test3
- mySQL Test2, Test4, Test5
- - All tests

The easiest way to include or exclude categories is through the graphical user interface of either csUnitRunner or the addin. Alternatively you can edit the recipe directly, which is an XML file and also includes the settings for the Category Selector.


Extreme Simplicity Logo

Agile Utilities Logo

Sources hosted by

Get csUnit - unit testing for .NET at SourceForge.net. Fast, secure and Free Open Source software downloads

Copyright © 2002-2009 by Agile Utilities NZ Ltd. All rights reserved. Site design by Andreas Weiss. This site is protected by bot traps.