PreviousNext

Analyze code coverage

The Coverage tools display a summary of code that has run. This feature/function is particularly useful when designing and running test cases because you can see what has been tested.

Run the Code Coverage tool

    1. Set two or more breakpoints in your code.
    2. Run the application to the first breakpoint.
    3. On the View menu, click Coverage.
    4. To reset information to 0, in the coverage pane, click Clear.
    5. Run the application to the next breakpoint.
    6. To display the percentage of code that has been run since you clicked Clear, in the coverage pane, click Refresh.

The Coverage pane displays the percentage of code that has been run. It displays a nested view of packages, classes, and methods, with the percentage of code executed in each.

View source code

> In the coverage pane, double-click a method.

Green bars in the source code indicate that the source code was run, and red bars in the source code indicate that the source code was not run.

Note: When you use the ternary if-else operator, the coverage tool displays accurate but misleading results. For example, your code might include the following statement:

a ? b : c;

if "a" is always true, then "c" will never execute; however, the coverage tool displays the statement as covered.

You can work around this by rewriting the code to avoid the ternary operator, as shown in the following code:

if( a ) {

} else {

}

The short-circuit logical operators && and || exhibit the same behavior.

Related topic


   BlackBerry