Setup and Run the First Test
Purpose:
This process will create a Web form in your Web Forms project which will
execute the tests you have created.
Starting Point:
The Region business object test class is complete.
Steps:
- In your Web Forms project, add a reference to your
Business Object Tests project. (
- Add a new Web form called TestForm to your Web forms
project.
- Drag a button from the Web Forms tab of the Toolbox
onto the center of the Designer window.
- Press F4 to display its properties.
- Change the ID property to 'regionTestButton'.
- Change the Text property to 'Test Region'.
- Set the AccessKey property to 'r'.
- Add a label control to the designer.
- Change its ID property to 'resultsLabel'.
- Change it's Text property to "Waiting to Run First
Test".
- Double-click on the new button to open the code window
in a new button handler. Note that this method adds all of the new
button's handler support code automatically.
- Import the Business Object Tests namespace to your Web
form code module.
- In the new handler, declare a RegionTest object
passing it the name of your XML data file.
- Call the test object's RunAllTests method.
- Add a line to change the Text property of the results
label to "All tests ran successfully." (Any error will crash the tests
before getting to this line.)
- Save the object. The finished code should look
something like this:
private void regionTestButton_Click(object sender, System.EventArgs e)
{
RegionTest myTest = new RegionTest(@"H:\TestData\Northwind\RegionTestData.xml");
myTest.RunAllTests();
resultsLabel.Text = "All tests ran successfully.";
}
- Place a break on the line that declares myTest.
- Set your new form to be the startup object.
- Make sure that your compile and run mode is set to
'Debug'.
- Compile, Save, and Run.
- When you reach the break point, use the F11 key to
step into each statement in order. If you run into an error, stop
debugging, fix the error, and restart.
- Continue until you can complete the test without
error.
Rationale
This will find the vast majority of the errors that are likely to be in our
code. The cost of creating and running the tests is nothing compared to
the cost of delivering code that contains errors.
Discussion:
This will take a while. It always does the first time. However,
you will find that most of the errors that you discover and fix will never occur
again. Other errors only occur the first time you run code in a new
solution, but fixing them at that point fixes them for the life of the project.
That's not to say that you will not have errors when you test the next set of
components, but you will likely have a different kind of error in the future.
Previous Step: Create the
Region Test Class
Next Step: Create the Regression Test
Class