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?
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.
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\..*
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:
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
Yes. If you're using the IntelliJ IDEA coverage runner, you need to switch it to tracing mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With