Code coverage - attribute driven exclusion

Hey there.

SonarCloud relies on the coverage report being generated to know what lines can be covered by tests (which lines are “executable”), and also which are excluded.

SonarCloud won’t do any post-processing of code (looking for the ExcludeFromCodeCoverageAttribute class), but it will listen to the coverage report.

You might have to explicitly tell your coverage tool to recognize this attribute (for example, for OpenCover requires adding -excludebyattribute:*.ExcludeFromCodeCoverageAttribute to the opencover.exe command line.

So my advice is to make sure everything is :100: in the coverage report you’re generating (coverage is being excluded as you expect). If somehow coverage is still getting reported in SonarCloud after, come back to us!

1 Like