Create a Regression Test Class

Purpose:

This class will contain the tests that will be run again and again.  It will also serve as an example of how to decorate classes and methods so that they are visible to the NUnit GUI.

Starting Point:

The Region business object test class must be complete.  You should have been able to successfully run the tests from your Web forms project.

Steps:

  1. Add a new class named RegressionTests to the Business Object Tests project.
  2. Import the NUnit.Framework library to your class.
  3. Create the following Regions in the body of your new class, Constructors and Public Methods.  Constructors’ on the next to mark the end. Then move the default constructor inside of this region.
  4. Add a TestFixture declaration to the line before the class declaration.  This makes it part of the declaration and lets the NUnit GUI know that this class contains tests.  The declaration lines should look something like this:

    [TestFixture]
    public class RegressionTests

    VB.NET users note that VB decorations use pointy brackets (<>) and must be followed by a line continuation character.
  5. Add a public void method named TestRegions.
  6. Decorate the new method using the Test decoration.  This lets the NUnit GUI know that this method is a test that it can call.
  7. Copy the test declaration and the run all tests line from the test button routine in your test class.  (You don't need the success message because the NUnit GUI provides its own success report.
  8. Paste the two copied lines in your new method.  You're done.  The finished code should look something like this:

    [Test]
    public void TestRegions()
    {
        RegionTest myTest = new RegionTest(@"H:\TestData\Northwind\RegionTestData.xml");
        myTest.RunAllTests();
    }
     
  9. Compile and Save

Rationale

This class allows the tests to be run from the NUnit GUI or the NUnit command line interface.  It is little work to create and even less to maintain.

Discussion:

Decorating the class and the tests is about the only difficulty here.  Once you do that, calling the tests is just like calling them from a form.

Previous Step: Run the First Test

Next Step: Run NUnit