using NUnit.Framework;
using NUnit.Core; // requieres nunit.core.dll
[TestFixture]
public class TestClassSuite
{
[Suite]
public static TestSuite Suite
{
get{
TestSuite suite = new TestSuite(@"Give it a name");
suite.Add(new Test1());
suite.Add(new Test2());
// add more test cases
return suite;
}
}
}
The classes you add to the suite (Test1 , Test2 and so on), are marked as [TestFuxuture] classes. Within each of these classes you still have the [Test] attribute on individual mehtods, and the framework will run those automaitcally. The suite facility doesn't stop you running the individual fixtures when you want. But they also let you group those fixtures: by running the one Suite(), you can now run a whole bunch of test fuxtures at once.
suites are a useful machanism for composing tests hierachically, which can be handy for coordinating sets of tests especially for an unattended build.
But it's not that useful a mechanism for day-to-day testing. You would like to be able to cross-cut across all the tests and select or exclude certain kinds of tsests from the vast pool of existing test you have written.
NUnit forces also another mechanism you can use to categroize ansd classify individual test methods and fixtures.
Categories
For instance, suppose you have got a few methods that only take a few seconds to run, but one method that takes a long time to run. You can annotate them using the category attribute.
using NUnit.Framework;
using NUnit.Core;
[TestFixture]
public class SampleCategory()
{
[Test]
[Category("ShortTest")]
public void TestMethod1()
{
// suppose this takes 1 min.
}
[Test]
[Category("ShortTest")]
public void TestMethod1()
{
// suppose this takes 1 min.
}
[Test]
[Category("ShortIntensiv")]
public void TestMethod3()
{
// suppose this takes 3 hours.
}
}
isn't it great . . . . . .
Friday, February 25, 2005
NUnit: Suites & Categories
at 12:46 AM Posted by roni schuetz
Subscribe to:
Post Comments (Atom)
Shared Cache - .Net Caching made easy
All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.
No comments:
Post a Comment