C# code coverage not reporting from Azure DevOps

Which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)?

  • SonarQube Developer Edition v8.9.1 build 44547
  • SonarQube DevOps extension version 5.0.0

What are you trying to achieve?

I am trying to get unit test and code coverage results published from our Azure DevOps build pipeline into SonarQube.

What have you tried so far to achieve this?

We are using Azure DevOps multi-staged pipelines defined in yaml. Relevant snippet of my pipeline yaml below:

- job: sonarqube
  displayName: Sonarqube Security Scan
  steps:
    - task: SonarQubePrepare@4
      inputs:
        SonarQube: SonarQube
        scannerMode: 'MSBuild'
        projectKey: [REDACTED]
        extraProperites: |
          sonar.cs.opencover.reportsPaths=$(Agent.BuildDirectory)/**/coverage.opencover.xml
    - bash: dotnet build
      displayName: Debug build for security scan
    - bash: make test
      displayName: Unit tests
    - task: SonarQubeAnalyze@4
    - task: SonarQubePublish@4
      inputs:
        pollingTimeoutSec: 300

The make test command runs the unit tests and generates the coverage report using coverlet using the following script. It generates a coverage.opencover.xml in the UnitTests directory.

#!/bin/bash
set -e

dotnet test ./test/UnitTests/UnitTests.csproj -p:CollectCoverage=true -p:CoverletOutputFormat=opencover

echo "Generating coverage report if you want to view it locally."
dotnet tool update -g dotnet-reportgenerator-globaltool
reportgenerator -reports:test/**/coverage.*.xml -targetdir:coveragereport

I have validated that the coverage.opencover.xml is being created in Azure DevOps, but for some reason I am still getting no test information in SonarQube.

Any help is very much appreciated!

Thanks.

Hello @Mike_P , welcome to the community!

We’d need the verbose logs to help on this. You can find instructions to generate them in Troubleshooting .NET performance problems.

Also, did you read Troubleshooting .NET code coverage import?