在intellij中查看条件覆盖范围

Omr*_*tor 5 junit unit-testing code-coverage intellij-idea jacoco

鉴于代码:

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

使用JUnit我测试foo(15,true)和foo(25,true)

IntelliJ将报告条件行已完全覆盖(绿色),但事实并非如此.

在使用Jacoco的Eclipse中,线条被正确标记为部分覆盖,条件为黄色.

IntelliJ是否有办法在条件级别进行覆盖?

yol*_*ole 9

是.如果您正在使用IntelliJ IDEA覆盖运行器,则需要将其切换到跟踪模式.