Building a Test Harness

All software should be tested, and the VB IDE offers a great mechanism for testing. Click the Start button on the toolbar in VB, or press F5, to cause VB to compile and run the software being coded in VB.

Because the project ConfigSeat is an ActiveX DLL, it cannot execute; instead, it must be consumed by another program that can execute. To test the class clsChair, another project should be created in the same IDE instance in which clsChair is being edited. The project needs to be an executable software program whose sole purpose is to test the class clsChair. A program that tests another program is often referred to as a test harness.

  1. In Visual Basic, choose File | Add Project to open the Add Project dialog box.

  2. In the New tab, choose the project template Standard Exe. A new project is created, called Project1, that includes a form called Form1.

  3. In the Project Explorer, right-click the new project and choose Set As Start Up.

  4. Rename the project clsChairTester.

  5. Currently, the clsChair class is not accessible in the test harness clsChairTester because the test harness does not have a reference to the ConfigSeat project. To set this reference, choose Project | References to open the project’s References dialog box shown in Figure 13-7.

  6. Choose the reference for the library ConfigSeat by checking the box next to it, and then click OK.

    click to expand
    Figure 13-7: Project References dialog box

    Remember 

    Opening the References dialog box will open the references for the currently selected project only. Editing the references applies to the currently selected project only. Other projects within a project group might become the currently selected project if a code file is selected from the respective project by an inadvertent slip of the mouse. The name of the active project window is also shown in the References dialog box title bar. Be sure to verify that the appropriate References dialog box is opened before you make any changes.

The form1 may be manipulated to show how various parts of the class clsChair function. A good strategy is to represent all class properties as text boxes and all functions as buttons, with text boxes for the arguments on the test harness form for the respective class. The test harness should be stored with the source code for the class that it tests, since it may be useful to future efforts to enhance or fix the class.

Note 

This test harness, clsChairTester, is stored with the source code of this chapter and will be made available on the author’s web site as mentioned in the book’s Introduction.

Because only one property exists to the class clsChair, the test harness will simply show and set the value of the property to the user. After pasting a few text boxes and a command button on the form, and writing code to create and manipulate the class clsChair according to the user interaction, you can test the chair component using the test harness.

  1. Press F5 to start the test harness. The output shows that the object was created successfully and the color of the chair is set to Brown.

  2. Type in a new color and click the Set New Color button.

Please refer to Figure 13-8 to see the test harness demonstrating the color property being changed successfully in a few tests.

click to expand
Figure 13-8: clsChair test harness testing the color property




IIS 6(c) The Complete Reference
IIS 6: The Complete Reference
ISBN: 0072224959
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net