Creating a Component Test for C

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:

  1. If the Project Explorer window is not visible, from the View menu, select Other Windows and Project Window.

  2. From the Window menu, select Close All.

  3. Click the toolbar Start button to relaunch the Start Page.

  4. Select the Activities link on the left-hand side of the Start Page.

  5. Select the Component Testing link that has now appeared.

  6. 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.

  1. 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:

 

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 OneTest Embedded works, you should select all functions in the file UmtsCode.c.

  1. Left-click the box to the left of every function in the source file UmtsCode.c (there are five functions in total).

  2. Click the Next button.

In the Test Script Generation Settings window, you are asked to make two decisions

  1. 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.

  2. 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.

  1. 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.