Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 957
Omri Spector Avatar asked Feb 10 '15 08:02

Omri Spector


People also ask

What is code coverage in IntelliJ?

Code coverage. Code coverage in IntelliJ IDEA allows you to see the extent to which your code has been executed. It also lets you verify the extent to which your code is covered by unit tests, so that you can estimate how effective these tests are. Code coverage is supported only for the classes and sources that belong to your current project.

How do I run a test class with coverage in IntelliJ?

Open the test class and go to Run => Run ‘SolutionTest.testSort’ with coverage Figure 3. Run with coverage IntelliJ will run the test class with the coverage option on. sampling ... com\.javacodegeeks\..*

How do I see Coverage metrics in IntelliJ IDEA?

I struggled for some time with finding the right buttons in Intellij Idea. Then at some point I found "run {project-name} with Coverage" in the menu. Push this and you will see coverage metrics when it is done running, below is an image of where this is in the menu:

What is base branch coverage in IntelliJ?

Branch coverage shows the percentage of the executed branches in the source code (normally, these are the if / else and switch statements). This information is available for the JaCoCo runner and for the IntelliJ IDEA runner with the Tracing option enabled. Code Coverage tool window options


1 Answers

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

like image 124
yole Avatar answered Oct 13 '22 16:10

yole