Using the Component Testing Wizard, you will now create a test for all functions in the file UmtsCode.c - including the code_int function that contains the while statement for which you wish to improve coverage.
To create a component test:
If the Project Explorer window is not visible, from the View menu, select Other Windows and Project Window.
From the Window menu, select Close All.
Click the toolbar
Start button to
relaunch the Start Page.
Select the Activities link on the left-hand side of the Start Page.
Select the Component Testing link that has now appeared.
In the Application Files window, notice how all the C source files of your development project are already visible.
Select the Compute static metrics option. This allows the measurement of code complexity from which you can prioritize your test campaign.
Click the Next button.
In the Components Under Test window, you are asked to specify which functions 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 just 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.
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 code_int function. However, to help you get a better understanding of how the component testing feature of Test RealTimePurifyPlus RealTimePurifyPlus for Linux works, you should select all functions in the file UmtsCode.c.
Left-click the box to the left of every function in the source file UmtsCode.c (there are five functions in total).
Click the Next button.
In the Test Script Generation Settings window, you are asked to make two decisions
If you've selected more than one function to test, do you want all functions to be part of the same test script (Single Mode) or do you want each function 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.
Type UmtsCode in the Test Name field - that is, name the test node after the source file whose functions you will be testing. Leave the default selections. You will be creating a single test script that automatically stubs all referenced but undefined functions. Click the Next button.
You should now be viewing the Summary window. Click the Next button.
The Component Testing Wizard now analyzes the source code in UmtsCode.c and creates a test for every function within it.
When test script generation has completed, click the Finish button.
In the Project Browser tab of the Project Explorer window on the right-hand side of the screen, you should now see a component test node named UmtsCode.