[SalesForce] Visual Studio Code Apex class code coverage colors

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.

VS Code Apex code coverage

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.

Developer Console code coverage


Investigation on the unknown color #5E5620 being somewhere between the known colors.

  • Green – Measured: #264C15 Source: #2D790B
  • Red – Measured: #8E3334 Source: #FD4849

enter image description here

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

These are then applied in /src/codecoverage/colorizer.ts. (Credit to @ThomasTaylor for pointing these locations out).

  const editor = window.activeTextEditor;
  if (editor) {
    editor.setDecorations(coveredLinesDecorationType, this.coveredLines);
    editor.setDecorations(uncoveredLinesDecorationType, this.uncoveredLines);
  }

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 in coveredLines. 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:

If a set of decorations already exists with the given decoration type, they will be replaced.

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.

Related Topic