AzureDevops C# opencover coverage not visible in SonarQube

  • Version: Version 8.6 (build 39681)
  • Plugin version: SonarQubePublish@4

We have a CI pipeline running unit tests that generates opencover.xml files and creates a code coverage html page for that.
We can see the code coverage, I can see these .opencover.xml files exist but sonarqube doesn’t seem to care about it very much.
I’ve already migrated it from coverlet to opencover because I didn’t see any documentation suggesting that the C# analyzer supports coverlet.
I’ve added these additional properties:

sonar.language=csharp
sonar.log.level=TRACE
sonar.verbose=true
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.vstest.reportsPaths=$(Build.SourcesDirectory)/**/TestResults/*.trx
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/TestResults/**/coverage.opencover.xml

SonarQube recognizes that I have tests so it’s detecting the trx files but it give’s me the following output:

Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
No code coverage attachments were found from the trx files.
Did not find any binary coverage files in the expected location.
Falling back on locating coverage files in the agent temp directory.
Searching for coverage files in D:\a\_temp
No coverage files found in the agent temp directory.
Coverage report conversion completed successfully.
Process returned exit code 0
The TFS Processor has finished

I’ve already looked at a lot of stackoverflow and articles within this community but they all seem to be slightly different from my issue.
I think the underlying issue may be that we don’t generate .coveragexml files but I don’t want to add more steps to my already pretty large pipeline if I don’t need to.

Hello Marvin,

Please note that SonarQube v8.9 is now the minimum supported version of SonarQube. You should consider an upgrade at your earliest convenience.

I believe that the analysis logs will have information that will help me to isolate what the issue could be. Please set your log level to DEBUG (not trace) and send me a zip of the log.


Regards,
Monty

Hi,
I double-checked and we’re actually on Version 8.8 (build 42792) and I imagine the maintainers will update shortly. I just copied from my last message, sorry.

About the debug log, how do I do that and what kind of information is stored in there?
We’re doing quite a sensitive project so I can’t just share anything.

Regards,
Marvin

I understand you may need to redact sensitive information. Logs are quite helpful, though. I’m wanting to discover is what the logs show that the analyzer thinks the value you gave for reportsPaths.

Hi Monty,

I’ve redacted a lot from the logs, but I think this should be all you need:
sonarqube-44193.zip (188.0 KB)

Kind regards,
Marvin Brouwer

Hi Marvin:

Your logs are insightful. The analyze log from line 10172 says:

INFO: Sensor C# Tests Coverage Report Import [csharp]
DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'D:\a\1\.' and file separator '\'.
DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\1' from the given pattern 'D:\a\1\s/**/TestResults/**/coverage.opencover.xml'.
DEBUG: Gathering files for wildcardPattern 's/**/TestResults/**/coverage.opencover.xml'.
DEBUG: Pattern matcher returns '0' files.
WARN: Could not find any coverage report file matching the pattern 'D:\a\1\s/**/TestResults/**/coverage.opencover.xml'. Troubleshooting guide: https://community.sonarsource.com/t/37151
DEBUG: Analyzing coverage after aggregate found '0' coverage files.
DEBUG: The total number of file count statistics is '0'.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=183ms

INFO: Sensor C# Unit Test Results Import [csharp]
DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\1' from the given pattern 'D:\a\1\s/**/TestResults/*.trx'.
DEBUG: Gathering files for wildcardPattern 's/**/TestResults/*.trx'.
DEBUG: Pattern matcher returns '0' files.
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=188ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=93ms

It seems the error is in your reportsPaths assignments: the warn statement said it could not find a report file, and referred to the troubleshooting guide [Coverage] Troubleshooting guide for .NET code coverage import

Let me know how Joe’s advice in this troubleshooting guide helps.


Regards,
Monty

1 Like

Hmm that is interesting, since we use that same value to generate a code coverage report for the azure DevOps summary with the same variable in fact.
I will have a look at the troubleshooting guide and get back to you.

I found the issue, it was actually this line that gave it away:

Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...

Which is true, but it’s not the only one.
So I tried changing:

  - task: SonarQubePrepare@4
    displayName: "📇 Prepare analysis on SonarQube"
    enabled: ${{ parameters.enableSonarQube }}
    inputs:
      SonarQube: SonarQube
      projectKey: [REDACTED]
      projectName: [REDACTED]
      extraProperties: |
        sonar.language=csharp
        sonar.log.level=DEBUG
        sonar.verbose=true
        sonar.exclusions=**/obj/**,**/*.dll
        sonar.cs.vstest.reportsPaths=$(Build.SourcesDirectory)/**/TestResults/*.trx
        sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/TestResults/**/coverage.opencover.xml

into:

  - task: SonarQubePrepare@4
    displayName: "📇 Prepare analysis on SonarQube"
    enabled: ${{ parameters.enableSonarQube }}
    inputs:
      SonarQube: SonarQube
      projectKey: [REDACTED]
      projectName: [REDACTED]
      extraProperties: |
        sonar.language=csharp
        sonar.log.level=DEBUG
        sonar.verbose=true
        sonar.exclusions=**/obj/**,**/*.dll
        sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/TestResults/**/coverage.opencover.xml

And now it works.

In my efforts to try to make it work I started adding these reportPath settings.
Now it appears that setting the sonar.cs.vstest.reportsPaths ignores the rest.
In my case that’s fine though because we only have opencover reports.

Thank you very much for your help>

With kind regards,
Marvin Brouwer

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.