I'm looking at the code coverage results from a recent run of all the tests in an org, and I'm not sure what all the colors represent.
The green and red seem fairly self explanatory:
- Green – covered by one or more test cases
- Red – not covered by any test cases
But what does the other color represent? I don't have the ability to describe that color, mustard maybe? Lets call it #5E5620.
Were those lines covered or not?
Note that all the test classes passed in the most recent run. So I don't think they represent failed test results.
Maybe something to do with partially covered lines? Although I'm not sure how that would work either. I don't believe the ApexCodeCoverage
can represent that. Also, how do you partially cover a line like sourceRecords.add(devObj);
?
For contrast, the developer console shows those lines as covered.
Investigation on the unknown color #5E5620 being somewhere between the known colors.
It gets a bit complicated with the alpha/opacity being applied in the editor and the grey background. But it does seem plausible that the unknown color is in between the two covered and uncovered colors.
I've raised this as an issue in the GitHub repo – Code coverage showing unknown color that isn't covered or uncovered
Best Answer
This seems probable, but I'm still very open to a better answer.
It's a bug in how the vscode extension is applying the covered and uncovered code coverage lines.
The styles for the covered and uncovered lines are currently defined in /src/codecoverage/decorations.ts as
uncoveredLinesDecorationType
andcoveredLinesDecorationType
.These are then applied in /src/codecoverage/colorizer.ts. (Credit to @ThomasTaylor for pointing these locations out).
So, first all the covered lines are colored green. Followed by coloring the uncovered lines red. As far as I can tell there isn't any consideration in building the
uncoveredLines
that those same line numbers already exist incoveredLines
. That is something I needed to explicitly handle when I made a code coverage viewer. Lines can appear to be uncovered in some test methods that are covered by other tests.The docs for
setDecorations
in the vscode docs aren't very clear on how multiple decorations are applied to the same line. It does say:It certainly appears they the styles get combined to give a color somewhere between covered and uncovered.
It doesn't really explain why line 124 in the screenshot above doesn't show the same behavior. It definitely isn't hit by all the test cases for that method.