5 View Code Coverage Output

After you have enabled code coverage, as described in Enable/Disable Code Coverage, debug your code and execute all test cases to completion. Then halt execution automatically or manually and step as needed till all code execution is complete.

To view code coverage:

  • Right click on project name and select “Show Code Coverage Summary” or select Window>Debugging>Code Coverage.
  • To see highlight in Editor window you may need to click in it. Covered code will be highlighted in the window.
  • To see highlight in Program (or Execution) Memory window, open it under Windows>Target Memory Views. Covered instructions will be highlighted in the window.
  • A summary report will be shown in the Code Coverage tab.
Figure 5-1. Code Coverage in MPLAB X IDE

Highlight Colors

The meaning of highlight colors in the Editor window and Program or Execution Memory window are described in the table below.

Highlight ColorHighlight NameMeaning
GreenCovered and Executed
YellowCovered and Partially Executed (Editor window only)
RedCovered but not Executed
No ColorNo coverage information generated1
Note 1: Reasons why no coverage information would be generated include:
  • Some C constructions may not generate code for a C source line
  • Optimizations may cause code not to be generated for a C source line

There may be other circumstances that C source lines do not produce executable code. See the examples in Understand Code Coverage Output.

Coverage Colors

On the Code Coverage tab, the colors on the bar chart under “Coverage” have the following meanings:

Coverage ColorCoverage NameMeaning
GreenTotal code covered and executed by test suite(s).
RedTotal code covered by test suite(s).

For more on this tab, see Code Coverage Window.

Code Coverage Tab Buttons

Click on buttons in the gutter of this tab for the following functions.

Generate HTML Report. This report will show the same data presented in the Code Coverage window.
Toggle (enable/disable) color highlighting in editor window.
Open Project Properties to enable/disable code coverage.