Running a C++ Component Test

You have set up your tests to increase coverage of the for loop in one of the PhoneNumber constructors by calling it with a value of 0. You have also set up two contract checks - one verifies that the phone number object is never full and empty at the same time, the other verifies that the phone number length is never set to 0. Time to run the test.

To execute the test node:

  1. Select the menu item Window->Close All

  2. Left-click the PhoneNumber test node (the parent node of the PhoneNumber.otd, PhoneNumber.otc and PhoneNumber.cpp nodes) and then press the Build toolbar button ()

  3. The test is executed as part of the build process - you will know the test has finished executing when the green execution light on the lower-right of the UI stops flashing.

  4. Select the menu item File->Save Project.

As with your C and Ada component test, the runtime analysis features are still selected in the Build options; the file under test - PhoneNumber.cpp - was instrumented for the memory profiling, performance profiling, code coverage and runtime analysis features, which explains why the Runtime Trace viewer appears during the run. Notice how the runtime tracing feature tracked all of the method calls made throughout the execution of the test.

So have you improved code coverage? Were any of your assertions violated? That is the subject of the next exercise.