Code Coverage from VSTS in SonarCloud Dashboard (coverlet)


(Christopher Wieland) #1

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?

(Emre Dundar) #2

Hi @Christopher_Wieland

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

(Christopher Wieland) #3

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)

(Emre Dundar) #4

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\"

(Christopher Wieland) #5

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

(Emre Dundar) #6

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

Please double-check the path is correct:


(Christopher Wieland) #7

Now it works perfect!

Thank you very much.