Question

I have a Jenkins job that is using the "Invoke standalone Sonar analysis" for a javascript project.

I thought it was working fine with the following parameters:

  sonar.sources=src
  sonar.language=js

  sonar.dynamicAnalysis=reuseReports
  sonar.javascript.jstestdriver.coveragefile=target/test-coverage/jscover.lcov
  sonar.javascript.lcov.reportPath=target/test-coverage/jscover.lcov

But then I noticed that the numbers that are being reported in Sonar do not match the number in the lcov file.

When I log into to Sonar I see the code coverage number as 30%.

But when I examine the lcov file, I get completely different numbers: $lcov --summary target/test-coverage/jscover.lcov ... lines......: 48.1% functions..: 41.7% branches...: no data found

And in fact, when I view the jscover.html report file, I see the total coverage at 48%. Sonar reports it at 30%.

And drilling down into the individual files, Sonar's results do not match the results in the lcov file either.

For instance: Just by looking at a particular file, /src/js/models/Call.js, lcov says it’s at 97% code coverage. But Sonar displays this: 49.0% by unit tests Line coverage:97.0% (97/100)Branch coverage:0.0% (0/98)

It’s as if Sonar is using the Branch Coverage AND the Line Coverage Stats to get the final code coverage results at 49.0%.

Do you know what I am doing wrong? Do you know why Sonar is not using the coverage results from the lcov file? Is it because the Branch Coverage has no data?

Thanks for any insight on this.

Was it helpful?

Solution

Code coverage is recomputed by SonarQube. SonarQube just retrieves from the report whether a line is covered or not by unit tests. Example:

  • DA:10,0 => it means that line 10 is not covered
  • DA:20,1 => it means that line 20 is covered
  • DA:30,5 => it means that line 30 is covered

Then SonarQube recomputes the code coverage:

  • Number of covered lines / (Number of covered lines + Number of uncovered lines)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top