TestSuite are suites of test dynamically created. This is a feature that was requested long ago and it finally poped up on my todo list. A TestSuite provides a way of creating dynamically TestCases with tightly-controlled naming. For example, in data-driven testing, you might want to create test cases based on some external data source.
How-to in MbUnit
To use suites, tag your calss with the TestSuiteFixtureAttribute attribute. Each method who creates suite must be tagged with TestSuiteAttribute and return a TestSuite, there can be multiple methods returning suites.
using System; using MbUnit.Core.Framework; using MbUnit.Framework; namespace MyNamespace { [TestSuiteFixture] public class MyClass { public delegate void TestDelegate(Object context); [TestSuite] public TestSuite GetSuite() { TestSuite suite = new TestSuite("Suite1"); suite.Add( "Test1", new TestDelegate( this.Test ), "hello" ); suite.Add( "Test2", new TestDelegate( this.AnotherTest), "another test" ); return suite; } public void Test( object testContext ) { Console.WriteLine("Test"); Assert.AreEqual("hello", testContext); } public void AnotherTest( object testContext ) { Console.WriteLine("AnotherTest"); Assert.AreEqual("another test", testContext); } } }
The resulting naming of the fixture will be as follows:
MyNamespace.MyClass.Suite1.Test1 MyNamespace.MyClass.Suite1.Test2
Not that the namespace name and the class name are used to create the test case name, the name of the method creating the suite is not used. The resulting output of the tests in MbUnit will look as follows:
Page rendered at Thursday, December 04, 2008 9:03:39 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.