6.1.1 Demo Code and Coverage Colors
For the case '\n'
statement shown:
- Both
if
statement conditions are executed and so shown as green (covered and executed). - Both
if
statements have evaluated as false and so the following functions are shown as red (covered but not executed). - The
else
of the secondif
statement applies and so the following function is executed and shown as green. - The
break
of thecase
statement is shown as yellow or partially covered (covered but partially executed) which seems unexpected as bothif
statements have executed. To understand what is going on with partial coverage it is useful to view the Program Memory window.
To see the view, shown in the image above:
- Halt program execution.
- Open the Program Memory window: Window>Target Memory Views>Program Memory.
- Place a breakpoint at the second
if
statement ofcase '\n'
. - Debug until the program pauses at the breakpoint.
- Step Into once.
In the Program Memory window, you can see the instructions for the
else
clause and break
statement. The compiler has
combined the jump back from the function call and the jump out of the
case
loop into one jump, which associates the
break
statement with the loop. Therefore it appears yellow since
the if
statement condition for true was never executed.
As you can see, viewing Program Memory can help you understanding why a line is partially covered (yellow). In general partially-covered lines can be minimized by writing tests to remove red lines (covered by not executed). Then the remaining yellow lines can be examined in assembly in the Program Memory window.