Running a component test is as simple as it was to build and execute the UMTS base station used in the runtime analysis exercises.
To execute the test:
Select the menu item File->Save Project.
Select the menu item Window->Close All
On the Project
Browser tab, right-click the PhoneNumber
Java component testing node and then select the Build
option OR left-click the PhoneNumber
Java component testing node and then select the Build
toolbar button ().
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. Wait for this to happen to ensure all test reports are created.
You may have forgotten that the runtime analysis tools are still selected in the Build options; the class under test - PhoneNumber - was instrumented (within the source file PhoneNumber.java) for the memory profiling, performance profiling, code coverage analysis and runtime tracing features of Test RealTimePurifyPlus RealTimePurifyPlus for Linux, which explains why the Runtime Trace viewer appears during the run. You'll look at the runtime tracing diagram in a moment - but just to be sure, check the Code Coverage viewer to verify that you have achieved greater coverage.
In the Project Window, right-click the PhoneNumber Java component testing node and select View Report->Code Coverage.
In the Report Window on the left-hand side of the UI, expand the PhoneNumber.java node, then expand the baseStation.PhoneNumber node, then left-click the removeDigit() method node.
As you can see, the majority of the removeDigit() method has been covered. Now to the runtime tracing diagram.
Select the Runtime Tracing Viewer tab.
Close the Project Window to the right and the Output Window at the bottom of the UI, hide the Coverage Bar, Thread Bar and Memory Usage Bar in the runtime tracing diagram, and set a zoom level of around 75% for the Runtime Trace viewer.
Notice how runtime tracing tracked all of the calls made by each test method. Of particular note is the Test Case lifeline, the fourth lifeline of the runtime tracing diagram. This lifeline represents each test class - that is, you should see a reference to testAddDigit, testRemoveDigit and testClearNumber as you move down the diagram.
Along this test class lifeline you should notice three things:
at the very beginning, a note containing the name of the test class
method calls directed at an instance of the tested class - in this case, obj0/obj1/obj2 of the PhoneNumber class
tiny glyphs representing
the actual tests performed in each test class - a pass is represented
by while a failure is represented by
. The
mouse tool tip, when the mouse is hovered over each glyph, indicates the
corresponding test.
A lot of information is contained in this runtime tracing diagram, which is why an additional test report is generated to simplify analysis of your test results.
Select the menu item View->Other Windows->Project Window.
On the Project Browser tab in Project Window, right-click the PhoneNumber Java component testing node and select View Report->Test.
Close the Project Window on the right-hand side of the UI.
What is the result of your tests? Did you improve coverage on the while statement? That is the subject of the next exercise.