Exercise 1.4: Checking code coverage

Before you begin, you must complete Exercise 1.3: Identifying a performance bottleneck.

Because you have collected line and method level coverage, you can display a copy of your code with annotations indicating which lines and which methods have been exercised during the run.

To display code with annotations and to check code coverage:

  1. In the Profiling Monitor, right-click the Profiling resource, and then select Open With > Coverage Details.
    The Annotated Source view and the Coverage Navigator view open.

  2. Note that the Annotated Source initially displays coverage statistics for the entire package. Here, 68.75% of the lines in the package were exercised, or hit, in this run. That's a relatively low coverage level, considering that a simple package like ours would not ordinarily have a lot of unexecuted branches.
  3. In the Coverage Navigator, expand the Default Package entry, then the Sort class entry, to display the coverage level of the methods in the Sort class.

  4. Double-click the quick method. The Annotated Source view changes to display the code for the method.

  5. Look at the vertical indicator on the right side of the Annotated Source view. The green and red bars on the indicator show the distribution of tested and untested code. Notice that there are large uncovered areas in the later part of the file.

    Tip: You can change the color of the green and red bars. To do this, select Windows > Preferences, and in the Preferences dialog box expand the entry for Profiling and Logging, and then in order the entries for Appearance and Annotated Source. Select Graphical Style, and change the colors for Uncovered Cell and Covered Cell.

     

  6. Scroll down until the scroll bar is opposite the first of the bars that indicate uncovered code. You'll see that it is the code for a method named quickFast. Glance back at the Coverage Monitor, and note that the indicator for quickFast confirms that this method was not tested.

You do not yet know exactly what the bottleneck is. However, you do know that there is a method, quickFast, that was not exercised. This is something to investigate. You are ready to begin Exercise 1.5: Resolving the performance bottleneck.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.