Opencover coverage report automatically added to sonar.exclusions property

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • how is SonarQube deployed: zip, Docker, Helm
  • what are you trying to achieve
  • what have you tried so far to achieve this

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

which versions are you using:
Sonarqube community 9.9

how is SonarQube deployed:
EKS cluster

what are you trying to achieve:
Trying to publish opencover reports to sonarqube

what have you tried so far to achieve this
I’ve added the following property in my pipeline SonarScanner.MSBuild.exe begin /d:sonar.cs.opencover.reportsPaths=coverage.xml and can see the coverage.xml file generated, I’ve also used reportgenerator to validate that there is coverage data. I noticed in the .sonarqube\conf\SonarQubeAnalysisConfig.xml that the property for sonar.exclusions is automatically set and set to the name of my coverage.xml file even though I am not setting this exclusion. I’ve tried setting the exclusion manually to something like /d:sonar.exclusion=test and the .sonarqube\conf\SonarQubeAnalysisConfig.xml just adds test along with my coverage.xml to the exlucsion property like test,coverage.xml

anyone seen this before?

Hi,

The path you supplied is automatically added to the sources exclusion path to make sure we do not analyze files in there for issues. This is expected and should not impair uploading the coverage to SonarQube.

Are you sure the path you provide is right though? Could you please provide us with:

  • Your version of the scanner for .NET
  • The (redacted if need be) logs generated from the begin and end step, if possible with the /d:sonar.verbose=true argument added to the begin step

Denis

Hi, @johnjohn

Looking quickly at your logs, it looks like some if your code refers to some sort of NUnit adapter.
If that is the case, I assume it references the NUnit package. This would probably automatically classify your code as “test code”, which would not be eligible for coverage.

If that is indeed your problem, you can help the analysis by specifying if a project is os is not a “test” project.
In the csproj of a miscategorized project, you need to add the following:

<PropertyGroup>
  <SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

Then you have a lot of files skipped because they are automatically ignored (*.designer.cs for example, or Service References). This is because they are considered auto-generated and ignored.

That being said, we do load and handle the coverage files:

11:46:06  11:46:04.238 INFO: Coverage Report Statistics: 803 files, 791 main files, 791 main files with coverage, 12 test files, 0 project excluded files, 0 other language files.

So you should already see some coverage information in your project.
What other symptoms do you see in the product that makes you say it does not work, exactly?
Do you see no coverage information at all on Overall Code?

Denis

Thanks @denis.troller. I’ve added the property to the project files and now seeing sonarqube reporting line coverage. I am still seeing 0.0% coverage on “overall code” but when I drill down to specific sections I can see coverage. Looks like the amount of uncovered lines vs lines to cover is so small that sonarqube reports 0.0%

Lines to Cover

152,447

Uncovered Lines

152,379

Hi @johnjohn

That seems right unless you know for a fact you have more tests than that (i.e. the reported covered lines count is wrong).

Denis