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:

  1. In your Web Forms project, add a reference to your Business Object Tests project.  (
  2. Add a new Web form called TestForm to your Web forms project.
  3. Drag a button from the Web Forms tab of the Toolbox onto the center of the Designer window.
  4. Press F4 to display its properties.
  5. Change the ID property to 'regionTestButton'.
  6. Change the Text property to 'Test Region'.
  7. Set the AccessKey property to 'r'.
  8. Add a label control to the designer.
  9. Change its ID property to 'resultsLabel'.
  10. Change it's Text property to "Waiting to Run First Test".
  11. 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.
  12. Import the Business Object Tests namespace to your Web form code module.
  13. In the new handler, declare a RegionTest object passing it the name of your XML data file.
  14. Call the test object's RunAllTests method.
  15. 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.)
  16. 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.";
    }
     
  17. Place a break on the line that declares myTest.
  18. Set your new form to be the startup object.
  19. Make sure that your compile and run mode is set to 'Debug'.
  20. Compile, Save, and Run.
  21. 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.
  22. 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