Search code examples
unit-testingintellij-ideajunitcode-coveragejacoco

Viewing condition coverage in intellij


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?


Solution

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