40
votes

As discussed in Open JaCoCo report in Intellij IDEA, when I gather code coverage statistics using Jacoco (rather than native IntelliJ tracing) 0.0% (i.e. "no" coverage) is always shown in the coverage window.

This is after I have done the whole "Analyze -> Show coverage data..." and selected my generated "jacoco.exec" file.

The same "jacoco.exec" file works fine with other tools such as the Jacoco native report generation task, and with Sonar, and these produce the expected coverage report content.

Also native IntelliJ instrumentation works fine.

Can anybody advise me if there is some essential step I must perform to get IntelliJ to accept my Jacoco coverage?

5
I've got same issue, and in my case, it seems to be related to Maven multi-modules layout. More details here. Unfortunately, no resolution yet.Feugy
Ah Jetbrains support, helpful as ever.robert
Do you have sane size of your jacoco.exec file? I've seen number of times that because of wrong JaCoCo configuration it actually didn't collect coverage and file was too small.Dmitry Zvorygin
How you run your test code for gathering code coverage? From Intellij IDEA ? or maven / ant?Nikhil
In the coverage tab of your IntelliJ, have you checked that the packages to enable coverage for are generic enough? I had once the problem that the list of packages in Coverage tab were something like "com.app.very.special.package.*" instead of "com.app.*"rdlopes

5 Answers

4
votes

When you add the class to PowerMockito annotation @PrepareForTest for the test classes, the corresponding class will not be showing the code coverage.

2
votes

For me the solution was to simply add the root package (in my case "de" in your case probably "com") to the "Packages and classes to include in coverage data". Now i see a reasonable Code Coverage. enter image description here

1
votes

I may guess you are trying to see test coverage in same way as it is show by the TeamCity(jaCoCo). If Yes there are simple workaround how to check all missed branches(just general statistic which branches was visited and how many times) :

enter image description here

enter image description here

That's all my advices , folks

1
votes

Buid source code through IntelliJ before importing jacoco.exec might be solved this showing 0% coverage problem.

-1
votes

"intellij idea" seems to have no way of showing correct coverage value of jacoco report created. It is indeed misleading and unfair when it shows coverage as 0.0 instead of giving an unsupport format error.

However, as an alternative, we can push jacoco report (created as part of maven build) to the sonar(qube) server using maven-sonar-plugin's target, sonar:sonar

mvn clean install sonar:sonar -Dsonar.host.url=http://<sonar-host>:9000 -Dsonar.projectKey=<sonar project key> -Dsonar.branch=<sonar project branch> -Dsonar.login=<sonar user> -Dsonar.password=<sonar pwd>

sonar.projectKey and sonar.branch properties value can be retrieved from corresponding project created in sonarqube.