Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Code Coverage (Unit Test Framework Toolkit)

LabVIEW 2013 Unit Test Framework Toolkit Help

Edition Date: June 2013

Part Number: 372584F-01

»View Product Info
Download Help (Windows Only)

Code coverage measures the percentage of subdiagrams LabVIEW executes when you run a VI. This measurement provides information about the amount of code that was executed and might be useful when performing unit testing.

Note  The LabVIEW Unit Test Framework Toolkit cannot measure code coverage on real-time (RT) targets.

The Unit Test Framework Toolkit calculates code coverage by dividing the total number of subdiagrams that execute during test execution by the total number of subdiagrams in the VI. Every VI has at least one subdiagram or diagram, which is the block diagram of the VI. Loops and structures have one or more subdiagrams. For example, For Loop and While Loop structures have one subdiagram each. Case and Sequence structures have one subdiagram per frame.

The previous figure shows the block diagram of a VI. You can assume that each Case structure contains only two cases and no loops or structures other than the For Loop that already appears in the figure. Using these assumptions, this VI contains six subdiagrams. The six subdiagrams are the block diagram of the VI, the two cases for each Case structure (four subdiagrams total), and the For Loop. If five of the six subdiagrams execute during test execution, the code coverage measurement is 83.33%.

You must allow debugging for each VI under test in order to measure code coverage. If the VI properties of a VI under test do not have a checkmark in the Allow debugging checkbox, the code coverage result always will be zero. To allow debugging, open the VI under test, select File»VI Properties to display the VI Properties dialog box, select Execution from the pull-down menu, and place a checkmark in the Allow debugging checkbox.

You can specify a minimum code coverage requirement interactively by using the Advanced page of the Test Properties dialog box. You also can specify a minimum code coverage requirement by editing .lvtest files.

When you execute a test, LabVIEW measures the percentage of subdiagrams covered for the VI under test. If the VI under test does not meet the minimum code coverage requirement you specified in the .lvtest file, test results show this test as failed. You can double-click an item on the Code Coverage page of the Unit Test Framework Results window to highlight the subdiagram of the VI that LabVIEW did not cover during execution.

If you test a member VI of a dynamic dispatch method, LabVIEW may execute another member VI in the test according to the method. The Unit Test Framework toolkit generates code coverage of the VI that LabVIEW executed in the test. On the Code Coverage page of the Unit Test Framework Results window, the Unit Test Framework toolkit uses a diamond (♦) to indicate a dynamic dispatch VI. The Unit Test Framework toolkit also lists all dynamic dispatch VIs of a test in the Dependencies list of this page.

Refer to the labview\examples\Unit Test Framework\Code Coverage\Code Coverage.lvproj for an example that demonstrates how to use code coverage.

Related Information

Case Structures: Executing a Section of Code Based on Input Values

Dynamic and Static Dispatch Member VIs

Loops and Other Structures

Sequence Structures: Executing Sections of Code Sequentially

Specifying a Minimum Code Coverage Requirement

Project Code Coverage

You can generate code coverage of a project by placing a checkmark in the Include VIs that were not tested checkbox on the Unit Test Framework page. When you execute this test, LabVIEW opens all VIs in this project to count subdiagrams and generates the code coverage of this project. For example, you can create a project that contains two VIs and each VI contains three subdiagrams and a test case that covers all three subdiagrams of one VI. When you execute this test, LabVIEW opens both VIs to count subdiagrams. Because this projects contains six subdiagrams and the test covers three subdiagrams, the project code coverage measurement is 50%.

Note  If a project contains a large number of VIs, opening these VIs can slow performance.

 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit