Specifying Test Authors, Categories, Importance and Targets

Both the MbUnit console runner and GUI runner allow you to run the tests in your project according to a number of criteria as follows

The GUI runner also divides up tests according to

Your tests will always be divisible into the namespace and class in which you have written them, but making them divisible by any of the other four criteria are purely optional. Should you wish to do this, each criteria can be applied to test fixture class (not an individual test) by adorning it with a specific attribute as follows.

Test Authors

Use the [Author] attribute to specify the name (email and website) of the test fixture’s author. For example

Copy 
[TestFixture]
[Author("Dan", "dan@hisemail.com", "http://docs.mbunit.com")]
public class MyFizzBuzzTests
{      
   [Row(1)]
   [Row(2)]
   [RowTest]
   public void ToFizzBuzz_SendNumberNotDivisibleBy3Or5_ReturnsNumberAsString(int NumberToTest)
   {
      Assert.AreEqual(NumberToTest.ToString(), 
         FizzBuzz.FizzBuzz.ToFizzBuzz(NumberToTest));
   }

   ... more tests ...
}

In this example, all the tests in the MyFizzBuzzTests class will be assigned the author “Dan”. If you don’t specify an author, MbUnit will give the fixture the default author value “Anonymous”

Test Categories

Use the [FixtureCategory] attribute to specify the category for the tests in the class. For example

Copy 
[TestFixture]
[FixtureCategory("Core Tests")]
public class MyFizzBuzzTests
{      
   [Row(1)]
   [Row(2)]
   [RowTest]
   public void ToFizzBuzz_SendNumberNotDivisibleBy3Or5_ReturnsNumberAsString(int NumberToTest)
   {
      Assert.AreEqual(NumberToTest.ToString(), 
         FizzBuzz.FizzBuzz.ToFizzBuzz(NumberToTest));
   }

   ... more tests ...
}

In this example, all the tests in the MyFizzBuzzTests class will be assigned the category “Core Tests”. If you don’t specify an category, MbUnit will give the fixture the default category value “Misc”

Test Importance

Use the [Importance] attribute to specify the importance of the tests in the class. For example

Copy 
[TestFixture]
[Importance(TestImportance.Critical)]
public class MyFizzBuzzTests
{      
   [Row(1)]
   [Row(2)]
   [RowTest]
   public void ToFizzBuzz_SendNumberNotDivisibleBy3Or5_ReturnsNumberAsString(int NumberToTest)
   {
      Assert.AreEqual(NumberToTest.ToString(), 
         FizzBuzz.FizzBuzz.ToFizzBuzz(NumberToTest));
   }

   ... more tests ...
}

In this example, all the tests in the MyFizzBuzzTests class will be classed as “Critical”. If you don’t specify an category, MbUnit will give the tests the default importance level “Default”. MbUnit defines five levels of test importance.

  • Critical
  • Default
  • NoOneReallyCaresAbout
  • Severe
  • Serious
Test Targets

Use the [TestsOn] attribute to specify the target class type for the tests in the class. For example

Copy 
[TestFixture]
[TestsOn(typeof(FizzBuzz.FizzBuzz))]
public class MyFizzBuzzTests
{      
   [Row(1)]
   [Row(2)]
   [RowTest]
   public void ToFizzBuzz_SendNumberNotDivisibleBy3Or5_ReturnsNumberAsString(int NumberToTest)
   {
      Assert.AreEqual(NumberToTest.ToString(), 
         FizzBuzz.FizzBuzz.ToFizzBuzz(NumberToTest));
   }

   ... more tests ...
}

In this example, all the tests in the MyFizzBuzzTests class are marked as testing the FizzBuzz.FizzBuzz class. If you don’t specify a test target, MbUnit will marks its target as “Unknown”