Purpose

This tool mentor describes how to use Rational TestFactory to measure and evaluate code-based test coverage for a Robot script that tests an application written in Visual Basic.

Related Rational Unified Process activities:

Overview

This Tool Mentor is applicable when running Windows NT 4.0.

To use TestFactory to evaluate code-based test coverage for a Robot script:

  1. Instrument the application-under-test.
  2. Play back the script.
  3. Review code coverage values for the script.
  4. Review the lines of source code covered.

1.   Instrument the application-under-test To top of page

To measure the code coverage of an executed script, you need to add instrumentation points to the application-under-test. The instrumentation points are counters that tally which parts of the code a script executes. You can instrument either the source code or the object code of the application.

If you have access to source code files, it is recommended that you instrument the source code for the application-under-test. The reasons for this are as follows:

  • TestFactory instruments source code at the branch level, while it instruments object code at the statement level. Branch coverage takes into account the if, then, and else conditions in instrumented source code, therefore TestFactory calculates more accurate code coverage values for instrumented source code than it can for instrumented object code.

Note: In some cases, the code coverage values calculated for an application-under-test with instrumented object code are slightly higher than those calculated for the same application-under-test with instrumented source code. The higher value is inflated as a result of statement-level object code instrumentation.

  • With access to instrumented source code, TestFactory provides more detailed coverage information on scripts than it can with instrumented object code.

To instrument object code, you must have an uncompressed version of the executable file, with symbolic debug information in a .pdb file.

To instrument the source code of the application-under-test:

  1. Start Rational TestFactory.
  2. Click Tools > Instrument, or click the Instrument button on the toolbar.
  3. In the Instrument Source Code dialog box, click Add.
  4. Select the Visual Basic project file associated with the application-under-test, and then click OK.
  5. If the application-under-test calls supplemental executable files and if you want to include these files in the code coverage metrics, do the following for each executable file:
  • Click Add.
  • Select the Visual Basic project file associated with the executable file, and then click OK.
  1. Click Instrument.
  2. When instrumentation and rebuild are complete, click Close.

To instrument the object code of the application-under-test:

  1. Obtain a copy of the application's .exe and .pdb files from a build that was compiled with the No Optimization and Create Symbolic Debug Info options selected.
  2. Start Rational TestFactory.
  3. Click Tools > Options.
  4. On the Instrumentation line, click Object code.
  5. Click OK.
  6. Click Tools > Instrument, or click the Instrument button on the toolbar.
  7. In the Instrument Object Code dialog box, click Add.
  8. Select the Visual Basic executable file associated with the application-under-test, and then click OK.
  9. If the application-under-test calls supplemental executable files and if you want to include these files in the code coverage metrics, do the following for each executable file:
  • Click Add.
  • Select the Visual Basic executable file, and then click OK.
  1. Click Instrument.
  2. When instrumentation is complete, click Close.

2.   Play back the script To top of page

Play back the Robot script in TestFactory. When you play back the script, two actions occur:

  • TestFactory passes the script to Robot to execute.
  • As the script executes, TestFactory monitors the instrumentation points in the code to tally the code coverage information.

To play back the script:

  1. In left pane of the TestFactory main window, expand the Robot Scripts folder.
  2. Under the folder, click the script that you want to play back.
  3. Click Script > Play Back, or click the Play Back Script button on the toolbar.

3.   Review code coverage values for the script To top of page

Review the code coverage information in TestFactory. When the script you played back is the active object in the left pane, the Coverage tab in the right pane displays an overall code coverage value—for both the application and all the instrumented supplemental executable file(s) called by the application. The tab also displays coverage information for each file and subroutine in the application.

To review the code coverage values for a script:

  1. If the script that you played back in TestFactory is not the active object in the left pane, expand the Robot Scripts folder, and then click the script.
  2. In the right pane, click the Coverage tab.
  3. Review the overall code coverage value.
  4. Expand the code coverage line.
  5. Review the code coverage values for the source files.
  6. Expand the code coverage line for a source file.
  7. Review the code coverage values for the subroutines in the source file.

4.   Review the lines of source code covered To top of page

Use the Coverage Browser in TestFactory to review the lines of source code that the script covered. If source code is available for the application-under-test, you can review each of the source files and examine which source statements were executed and which were not.

To review the lines of source code covered:

  1. Review code coverage values for the script.
  2. On the Coverage tab, determine the source file for which you want to review the code coverage and the first subroutine in the source file that you want to examine.
  3. Double-click the subroutine line that you chose in step 2. The Coverage Browser window opens, with the source file scrolled to display the subroutine at the top of the window.
  4. In the Coverage Browser window, use the buttons and boxes in the top area of the window to do the following:
  • To jump to the next line of code not covered by the script, click the Next Not Covered button.
  • To go to a specific line of code, type the line number in the left box, and then click the Go To Line button.
  • To go to a line of code that contains a specific text string, type the text in the right box, and then click the Find Text button.
  • To review all the lines of code in the file, use the scroll box. To determine the color code used for the different segments of text, click the Coverage Text Colors button.
  1. Close the Coverage Browser window.
  2. To review the lines of code that the script covers in another source file, return to step 2.
 

Display Rational Unified Process using frames

 

© Rational Software Corporation 1998 Rational Unified Process 5.1 (build 43)