Viewing condition coverage in intellij
Asked Answered
W

2

8

Given the code:

public void foo(int age,boolean smart) {
  if (age>18 && smart) { // <--- This is the part that should be covered
    doSomething()
  }
}

Using JUnit I test foo(15,true) and foo(25,true)

IntelliJ will report that the condition line was fully covered (green), but it was not.

In Eclipse using Jacoco the line is correctly labeled as partially covered, and the condition is colored yellow.

Is there a way for IntelliJ to give coverage at the condition level?

Willenewillet answered 10/2, 2015 at 8:34 Comment(1)
confluence.jetbrains.com/display/IDEADEV/IDEA+Coverage+RunnerOrthochromatic
S
16

Yes. If you're using the IntelliJ IDEA coverage runner, you need to switch it to tracing mode.

Salesin answered 10/2, 2015 at 8:35 Comment(3)
Great, I was under the impression that the branch was already covered in Sampling. I have to now go back to check few of my 100% code covered tests :DPerformance
This worked fine for me to. I was relying on the analysis made by SonarQube for this info. Now I can get the info locally also. Thanks.Clerc
In the newer IDE versions, the option seems to have changed, it's now known as "Enable branch coverage and test tracking".Cytochemistry
P
1

As a reference where to find the setting in IntelliJ IDEA 2022.3.3 (I didn't find it that easily, I was expecting it to be a global setting) enter image description here

Pippa answered 28/3, 2023 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.