Is sonar use jacoco internally for code coverage?

Hi Team,

can any one help me understanding what technique used by SonarScanner for code coverage in general?

Thanks,
Tapas

Hi,

the documentation Test coverage overview has

SonarSource analyzers do not run your tests or generate reports. They only import pre-generated reports.

The reports from coverage tools (Jacoco …) are consumed by Sonarqube.
It’s the same with other linters, see Importing third-party issues

Gilbert

Ok, if that is the case, even if I don’t include any of my test coverages which is by Jacoco still I can see some coverage reports by sonar on dashboard which quite different from my original jacoco one? Can anyone help me understand how sonar do the coverage report by itself absence of jacoco plugin ??

Hello @Tapas.nayak

I believe you will find answers in “executable line of code” documentation, especially the following:

Executable lines data is used to calculate missing test coverage for files that are not included in coverage reports. Ideally, executable line counts will be at or just under what coverage engines would calculate.

If you are not importing any coverage report, it will always result in 0% coverage. If it is not the case, it means that a report was imported in some way or another. I know that the Jacoco plugin is able to automatically import the report if everything is configured as expected, maybe it the case for you?

In addition, if the coverage is different than the one from Jacoco, it is possible that the report is missing some files (test files, other languages, …), and therefore using executable line as default, changing the total coverage.

To know exactly what is happening, you can have a look at the logs.
Hope this leads your research,

Quentin

1 Like

@Quentin we meet the issue about coverage is different than the one from Jacoco, would you explain it more clearly about the reason?
what the log should be check? the maven sonar plugin log?

Hello @aximo ,

This thread is almost 4 years old, a lot of things might have changed since the initial discussion.

In order to have a more focused discussion, and help us to better understand the situation, it would be great if you could open a new thread, describing more precisely your situation.
For example:

  • What are the differences you are observing? Were you able to identify specific differences?
  • A quick description of your project setup. Is your project multi-language? Do you have coverage-specific configurations?
  • Share the Scanner logs (or part of them). In your case, I was referring indeed to the Maven Scanner logs.
  • Did you already find clues on what could be going on?

I hope it will help you to quickly understand the situation.

Cheers,
Quentin