Code Coverage is not reflecting on SonarQube

Hi team,

I am performing SCA and code coverage of .NET core application from Azure Pipeline to SonarQube. Where I am able to generate the Open Cover after executing test cases and able to see the Code Coverage on Azure DevOps. But not able to See the Code Coverage percentage on SonarQube. Where I am able to see the " - " instead of percentage.

Using SonarQube 9.9 Community version.

Hi,

It sounds like you’re not passing a coverage report into analysis. The docs should get you started.

 
HTH,
Ann

Hi Ann,

I have tried with Coverlet to generate the Code Coverage and added all the properties mentioned over there.

I am performing this for multiple Dot Net Core Applications but facing the issue for one application where I have followed the similar process for all the applications.

NOTE: I am able generate the report with name Opencover.xml having the Coverage data and able to see the result of the file on Azure DevOps Code Coverage tab but not able to see the result to the SonarQube. Where I am able to " - " instead of Numbers.

Let me know if you require any other data.

Thankyou.

Hi,

Please share your analysis configuration and a debug analysis log.

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@3
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'dotnet'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Ann

Hi Ann,

As per the request attaching the Logs of Azure pipeline where SonarQube is integrated.
Pipeline_logs.zip (280.3 KB)

Let me know if you require any other details.

Please provide us the appropriate solutions for this issue.

Hi,

Here’s what I see in your log:

2025-02-07T06:31:11.4250219Z INFO: Sensor C# Tests Coverage Report Import [csharp]
2025-02-07T06:31:11.4266048Z INFO: Parsing the OpenCover report E:\*****\vsts-agent-win-x64-3.220.5\_work\41\s\Unittest\coverage.opencover.xml
2025-02-07T06:31:11.4930676Z INFO: Adding this code coverage report to the cache for later reuse: E:\*****\vsts-agent-win-x64-3.220.5\_work\41\s\Unittest\coverage.opencover.xml
2025-02-07T06:31:11.4978749Z INFO: Coverage Report Statistics: 20 files, 0 main files, 0 main files with coverage, 20 test files, 0 project excluded files, 0 other language files.
2025-02-07T06:31:11.5000804Z WARN: The Code Coverage report doesn't contain any coverage data for the included files. Troubleshooting guide: https://community.sonarsource.com/t/37151
2025-02-07T06:31:11.5001706Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=73ms

Here’s the troubleshooting guide referenced in the log.

 
HTH,
Ann

Hi Ann,

I have checked the URL that you have provided for Troubleshooting guide for .NET code coverage import where we have followed all the process which is required by using Open Cover.

Please find the attachment of the Azure Yaml where SonarQube is integrated and let me know the possible solutions for this.
Azure.txt (6.2 KB)

Let me know if you require any other details.

Thank you.

Hi,

extraProperties: "# Additional properties that will be passed to the scanner, \n# Put one key=value per line, example:\n# sonar.exclusions=**/*.bin\n#sonar.cs.opencover.reportsPaths=\"$(Build.SourcesDirectory)\\Unittest\\coverage.opencover.xml\"\nsonar.cs.opencover.reportsPaths=\"$(Build.SourcesDirectory)\\Unittest\\coverage.opencover.xml\"\nsonar.verbose=\"true\""

I’m not sure you’re passing the extra properties you think you are. You’ve double-quoted the whole value including linebreaks and comment markers (#). I suggest you clean that up, if only for your own sanity when you need to edit this later.

Beyond that, posting your yaml file doesn’t really address the problem cited in your log:

The Code Coverage report doesn't contain any coverage data for the included file

 
HTH,
Ann