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:
- Add a new class named RegressionTests to the Business Object Tests
project.
- Import the NUnit.Framework library to your class.
- 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.
- 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.
- Add a public void method named TestRegions.
- Decorate the new method using the Test decoration.
This lets the NUnit GUI know that this method is a test that it can call.
- 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.
- 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();
}
- 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