Using the Component Testing Wizard, you will now create a test for all functions in the file PhoneNumber.java - including the removeDigit() method that contains has not yet been covered.
To create a Java test node:
From the Window menu, select Close All(and close the Output Window at the bottom of the UI if you wish to free up additional space.
On the toolbar, click
the Start Page button.
Select the Activities link on the left side of the Start Page.
Select the Component Testing link in the center of the Start Page.
In the window Application Files - Notice how all source files of your project are already visible. No changes need to be made, so simply click the Next button. Static metrics are recalculated.
In the Components Under Test window that has now appeared, you are asked to specify which classes you would like to test. There are a variety of ways for making this decision. One method is to use the static metrics that have been automatically calculated. Certain measurements of code complexity are listed for you:
V(g) - Also called the Cyclomatic Number, it is a measure of the complexity of a function that is correlated with difficulty in testing. The standard value is between 1 and 10. A value of 1 means the code has no branching. A function's cyclomatic complexity should not exceed 10
Statements - Total number of statements in a function.
Nested Level - Statement nesting level.
Call to Components - Number of calls to methods defined outside the class.
Utilization of Variables - Number of uses of attributes defined outside the class.
Sorting by any of these metrics columns - by left-clicking a column header - lets you prioritize your test selection, choosing the more complicated functions first.
Additional metric information can be viewed by selecting the Metrics Diagram button on the lower right-hand side of the screen. Selection of this button opens a graph enabling visualization of two, selected static metrics graphed against one another. Select a data point in this graph to indicate your desire to test the associated functions.
For this Tutorial, your test selection is based on the desire to increase code coverage, so the static metrics do not affect your decision. You need to test the removeDigit() method, which is a part of the PhoneNumber class.
In the window Components Under Test, select the checkbox next to the reference to the PhoneNumber class. Click the Next button.
In the Test Mode window that has now appeared you are asked to make two decisions:
If you've selected more than one class to test, do you want all classes to be part of the same test script (Single Mode) or do you want each class to be assigned to its own test script (Multiple Mode). A single test script would be easier to manage, but multiple test scripts let you provide custom Configuration settings to each test.
Do you want Test RealTimePurifyPlus RealTimePurifyPlus for Linux to make some basic assumptions about test harness and test stub generation? If so, use Typical Mode; if not, use Expert Mode.
In the Test Script Generation Settings window, enter the name PhoneNumber into the Test Name edit box then click the Next button.
You should now be viewing the Summary window. Click Next.
Click Finish.
From the File menu, select Save Project.
Notice how, in the Project Browser tab on the right-hand side of the screen, a Java component testing node named PhoneNumber has been added to your project.