42

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?

Community
  • 1
  • 1
robert
  • 4,612
  • 2
  • 29
  • 39
  • 4
    I've got same issue, and in my case, it seems to be related to Maven multi-modules layout. More details [here](https://devnet.jetbrains.com/message/5532511). Unfortunately, no resolution yet. – Feugy Nov 26 '15 at 13:24
  • 1
    Ah Jetbrains support, helpful as ever. – robert Nov 26 '15 at 13:58
  • 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 Jun 13 '17 at 12:24
  • How you run your test code for gathering code coverage? From Intellij IDEA ? or maven / ant? – Nikhil Jun 21 '17 at 23:35
  • 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 Nov 19 '17 at 08:48
  • Running JUnit5 tests with JaCoCo configured through Gradle and showing these coverage statistics in Intellij IDEA seems to be working for me. Using Intellij IDEA 2017.2.6 with Coverage plugin 72.4574.11, Gradle 4.4.1, JUnit 5.0.3 and JaCoCo 0.7.9 . Could you provide additional details on how your coverage data was collected (Maven, Gradle, etc) and versions of your tools? – François POYER Feb 20 '18 at 13:50
  • It's a long time ago, but as far as I recall I was using the standard ant task. I don't know about your configuration but the fact that this question is still getting upvotes more than 2 years later suggests others are still having the problem. As far as I can make out the issue was probably something to do with IDEA not parsing the jacoco.exec file correctly, or at least failing to anticipate some kind of permutation in the format. – robert Feb 20 '18 at 16:05
  • If I'm looking at this area again in the near future I'll post an update for you. – robert Feb 20 '18 at 16:06

5 Answers5

4

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

Lore
  • 1,286
  • 1
  • 22
  • 57
Ram
  • 49
  • 4
2

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

2

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

L.Nightman
  • 69
  • 4
1

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

Andrew
  • 122
  • 7
  • 2
    Thanks andrew for your help. Indeed, this is what I am doing, however if you click the combo box for choose coverage runner there is an option for JaCoCo. There is the option to import JaCoCo coverage from an externally generated `jacoco.exec` under the 'Analyze' menu. It is this function that is not working for us. – robert Nov 26 '15 at 16:08
  • If you have some configuration issues you can try another workaround - connect to Teamcity via plugin (I believe it can show you code coverage in same way) – Andrew Nov 26 '15 at 20:02
-1

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

TT.
  • 15,774
  • 6
  • 47
  • 88
Shakti Garg
  • 263
  • 3
  • 15