No coverage in 'all classes in scope' in Intellij
Asked Answered
L

4

23

In Intellij IDEA 14.1.5 Community edition, I imported maven to get coverage from jacoco.exec file. Steps followed

  1. right click on imported module.

  2. select Analyze-->Show Converage Data.

  3. provided valid jacoc.exec file and click 'show selected'

Instead of coverage i'm getting error as no coverage in 'all classes in scope'

can anybody suggest what is wrong?

Longspur answered 3/11, 2015 at 10:39 Comment(2)
Can you try to downgrade jacoco to 7.4.x or earlier?Goggle
I'm using Jacoco 0.7.8 and seeing this in IntelliJ as wellPavior
G
29

I had the same thing happen to me.

I was able to fix this by going to "Edit Configurations", to the "Code Coverage" tab.

I'm not sure what caused it, but the wrong package namespace was listed there. I updated the entry there and my subsequent test run with code coverage succeeded.

Gardenia answered 27/5, 2017 at 0:18 Comment(1)
just FYI for me this happened because the package structure of my test code and my productive code didn't match. So my class was in foo.bar.baz.myclass and testclass was in foo.bar.mytestclassFinagle
A
17

It happens if your test class and class to test are in different package structures.

My test class was in:

com.tools.api

Class to be tested was in:

com.tools.ws

Once I've corrected the pattern as com.tools.* in the code coverage tab, I was able to see coverage results.

Autoxidation answered 18/2, 2019 at 4:16 Comment(3)
Thank you! It turns out that IntelliJ makes a poor choice about what coverage you want to see when you choose to only run one test. It creates a new Run Configuration when you choose to run only one test class or one package of test classes. It defaults to only recording coverage for classes that are in the same package as the test. That caused a problem for me since I sub-package my tests sometimes. This answer clued me into that fact.Valuation
Matching the classes and test classes is probably the best for consistency and readability anywayMyrlmyrle
Thanks for the solution. I like to add another packacke named "unit" or "integration" because e.g. I test the service class as a unit test ( with moching the db ) and as integration test ( with a test db). I know this can be deone with naming the class MyServiceUnitTest and MyServiceIntegrationTest but I like the additional strucuture. So defining the included packe solves the problem.Mothball
T
6

I was able to fix this issue by:

  1. Open Edit Configurations menu
  2. Click on Modify Options > Coverage settings > Specify classes and packages screenshot of run configuration settings
  3. In the new box that appears, click on the plus to add a package enter image description here
  4. Select a high level package from the project
Twist answered 19/7, 2021 at 19:58 Comment(1)
This worked in my case. thanks!Boogiewoogie
Y
5

I had the same problem and found solution here.

In the Code Coverage tab, define the following options:

Specify the scope to measure code coverage for. Do one of the following: To specify a class, click the Add Class button.

To specify a package, click the Add Package button.

Yuji answered 29/3, 2019 at 4:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.