Code Coverage
- Updated2025-11-07
- 3 minute(s) read
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 following picture shows an example block diagram with six subdiagrams:

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