7

I am analysing a Java project that has been unit tested and Cobertura coverage.xml reported. I am using SonarQube 4.1.1 and latest Sonar Runner. I have successfully imported Cobertura coverage results to Sonar 3.2 and Ant analyzer, but with this new version I am running into problems. In the new Sonar analysis execution (through Jenkins) I see no reference in logs that it would have started any Cobertura engine or anything. My settings in Runner Jenkins project:

sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=cobertura
sonar.cobertura.reportPath=[mypath]/coverage.xml
sonar.junit.reportsPath=[mypath]/

No mentioning of Cobertura in the analysis output (except my own property values) and SonarQube page shows "-" in coverage report. Unit test results are shown fine.

I have also added all source, bin, and test directories. Any ideas? Thanks.

Update I wonder if the reason why Cobertura coverage is not reported on SonarQube page, is because in Jenkins my SonarQube project clones (Clone plugin) the workspace from a previous Project build? If the coverage.xml file contains static paths, then maybe it goes wrong somehow.

user1340582
  • 19,151
  • 35
  • 115
  • 171

3 Answers3

3

Ok the solution was quite obvious. SonarCube 4.1.1 does not come with Cobertura preinstalled, so I installed it and now it works :) Maybe it was preinstalled in 3.2 version, I can't remember.

user1340582
  • 19,151
  • 35
  • 115
  • 171
  • 1
    How you installed it..and what steps you followed to get coverage in sonar. – Amit Kumar Mar 13 '14 at 16:54
  • 1
    The solution may sound obvious but the symptoms definitely don't make it obvious... There should be some sort of warning or error message in the logs. @amit_kumar as an admin on SQ, go to the Update Center and look for the Cobertura plug-in. (that applies to the server, not the client) – MisterStrickland Aug 30 '16 at 17:29
0

For any "reuse reports" feature in SonarQube (may it be for code coverage, test execution or any other third-party tool that generates a intermediate report), the report must be generated based on the same source files (in terms of file system location) than the ones that will be used for the SonarQube analysis. Otherwise the SonarQube plugins won't be able to match paths from the reports with paths of the analyzed sources.

So you guessed it right: cloning the workspace and running the SonarQube analysis on this clone is the reason why the coverage can't be computed.

  • Hmm I think it still does not work. I now built, tested, and ran code coverage on the build. Then I ran SonarQube analysis, but it still didn't pick up coverage. The keyword "Cobertura" doesn't even come up in the Sonar Runner output, which makes me think that something else is wrong. – user1340582 Feb 20 '14 at 14:05
0

The root cause of this problem is that SonarQube does not support Cobertura format and you need OpenCover, or dotCover format. Using reportgenerator is one of the solutions but it's unnecessary complicated: you can make "dotnet test" command to return the report in Opencover format by passing special parameter and then pick up the Opencover report.

Use

dotnet test --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover

to get two reports: one in OpenCover format for SonarQube and default Cobertura for Azure DevOps.

Now you can specify the path to OpenCover report in SonarQubePrepare task.

There is also detailed article on this here

Alex Langer
  • 456
  • 4
  • 10