Coverage Report Doesn't Match Open Cover when using .runsettings configuration

Template for a good new topic, formatted with Markdown:

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C#

I have a project set up in DevOps which generates an OpenCover report and pushes it to Sonar Cloud.

However, the output I’m seeing in Sonar Cloud doesn’t match the report. I’m using run settings to only include certain assemblies. And I can see this is the case when I look at the opencover.xml but in Sonar Cloud I can see a number of files appearing as “uncovered” which aren’t in the report.

Also the summaries don’t match, my xml report shows a sequenceCoverage of 56.89% and Sonar Cloud shows a coverage metric of 41.7%

Can someone tell me what’s going on here and how I can get Sonar Cloud to respect the report properly?

Hello @Sean_Comiskey

We have an open ticket for support runsettings.xml : #1487. To quote from there:

As a short-term answer, you will need to provide a new parameter (sonar.coverage.exclusion=LIST_OF_FILES) to the scanner for msbuild / .NET (or the prepare task of TFS/VSTS) OR configure your project on the SonarQube/SonarCloud project administration page to exclude all files you have excluded in your .runsettings file. Note that you can only exclude a file or a group of files BUT not something with a lower granularity.

Regarding file exclusions, you can read:

  1. Narrowing the Focus
  2. you can also exclude projects via the Scanner for MSBuild / .NET
  3. you can exclude specific classes with the ExcludeFromCodeCoverage attribute like explained here

Options 1 and 2 will exclude the files from analysis, in general, not only from the code coverage

Option 3 will exclude the classes only from code coverage.