Code Coverage from VSTS in SonarCloud Dashboard (coverlet)

HI there,

I have a build in VSTS to get the Code Coverage via cobertura. I do also Run the Code Analysis and publish the results via SonarCloud in the build.

The problem by now is, that it isn’t possible to watch the code coverage also in the SonarCloud Dashboard. Is there a common way by now?

1 Like

Hi @Christopher_Wieland

Is your code dotnet core or java? How do you generate cobertura report?

The Code is dotnet.

I generate the cobertura report with a dotnet command via reportgenerator:

“-reports:$(Build.SourcesDirectory)\TestResults\Coverage\coverage.cobertura.xml” “-targetdir:$(Build.SourcesDirectory)\TestResults\Coverage\Reports” -tag:$(Build.BuildNumber) -reportTypes:htmlInline

and the code coverage will be shown in the build task in the end. (only in VSTS)

I work on the same issue actually.
While VSTS supports Cobertura format, SonarQube doesn’t support it.
SonarQube supports Opencover, VSTS does not.

I think you use coverlet to get coverage report. As a workaround, I use multiple output format generation property of coverlet. VSTS parses cobertura xml and shows coverage report on build summary, SonarQube parses opencover xml.

You may try this way…

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutputFormat=cobertura

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover,cobertura\"

1 Like

I have tried it in both ways, but it didn’t work. I actuall used the following command to generate both formats in the dotnet test:

It also generate both formats:

Calculating coverage result…
2018-07-13T07:32:50.6208450Z Generating report ‘D:\a\1\s\TestResults\Coverage\coverage.cobertura.xml’
2018-07-13T07:32:50.7405391Z Generating report ‘D:\a\1\s\TestResults\Coverage\coverage.opencover.xml’

I can imagine, that only one step is left to publish the generated report to sonarcloud, but I cannot say, which

Yes, you are right :slight_smile:
The last step is passing a parameter to SonarCloud.

Please double-check the path is correct:


1 Like

Now it works perfect!

Thank you very much.

1 Like

If anyone is trying to do this in Azure Devops YAML, here is what worked for me for the dotnet test task:

 - task: DotNetCoreCLI@2
      displayName: dotnet test
        command: test
        arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true "/p:CoverletOutputFormat=\"opencover,Cobertura\""'
        projects: 'test/**/*Tests.csproj'
        nobuild: true