Using Code Coverage to Find Untested Code

Creating and executing a component test for C++ in HCL OneTest Embedded is much like the process for C and Ada component testing. Most steps are shared in common - the main difference is the content of the C++ component tests themselves, which you will see later.

As with the C and Ada testing exercises, the first step in these exercises is to use the code coverage feature of Test RealTime to determine which parts of your code require greater coverage.

To locate uncovered code:

  1. From the Window menu, select Close All.

  2. In the Project Browser tab on the right-hand side of the screen, right-click the BaseStation application node and select View Report->Code Coverage - that is, open the coverage information pertaining to your manual interaction with the UMTS base station.

  3. Maximize the Code Coverage viewer

  4. In the Report Window on the left-hand side of the screen, open the PhoneNumber.cpp node and then select the node for PhoneNumber(unsigned int)

Looking at the coverage for this constructor of the PhoneNumber class, you can see that the for loop has only been covered in one of three possible ways - you still need to cover 0 loop and 1 loop through the for statement.

To achieve this coverage, you would be wise to create an automated component test. Of particular interest would be to see what happens when a phone number of zero length is sent to the UMTS base station. The objective of this tutorial is to increase code coverage by ensuring this PhoneNumber constructor is called with a value of 0.