JaCoCo with IntelliJ
Solution 1
To elaborate on jwenting's answer, go to Run > Edit Configurations..., and on the Code Coverage tab of your Run Configuration, select JaCoCo from the Choose coverage runner dropdown.
Solution 2
You don't need to do anything, if you have a recent version of IntelliJ. Just select to use JaCoCo as the coverage tool in the run configuration for your test suite or project and it will use its built-in JaCoCo version.
Solution 3
Have you looked at this document : https://www.jetbrains.com/help/idea/2017.1/code-coverage.html
They describe how to do such a task.
Solution 4
Intellij shows code coverage in the IDE. There is no need to install any extra plugins
when you right click on a Test.java file to run the unit test then there will be 3 options
Run "Test"
Debug "Test"
Run "Test" with **coverage**
Secondly, if you also want the branch coverage details then,
after running the test(as mentioned above) once, then then go to edit configuration -> at left side under Junit select the respective Test.java file -> select Code Coverage tab in the main window -> select Tracing radio button and tick the Track per test coverage checkbox
Solution 5
With IntelliJ 2021.2.1 (and possibly prior to that), Jetbrains switched the default to a bundled code coverage runner they provide. But it does not provide branch coverage, as JaCoCo does. JaCoCo is not listed in Plugins, but it was available as an alternative for me (perhaps because it's in the Maven POM).
The solution above using Run -> Edit Configurations will change a single run configuration (e.g. for a single JUnit test class). To change it for all new ones, after going to Run -> Edit Configurations, click Edit Configuration Templates on the lower left, and change the coverage runner there.
Related videos on Youtube
Ixbitz
Updated on July 09, 2022Comments
-
Ixbitz almost 2 years
So this question might not be really specific, but i'm asking it anyway.
I'm trying to use JaCoCo with IntelliJ to gather coverage reports on unit tests. However, i don't have any experience whatsoever to set this up.
In Netbeans you just have to install the JaCoCo plugin and select to test with coverage. How does this work in IntelliJ?
I have googeled for quite a while without success. If someone has a good tutorial to set this up, i'd really appreciate it!
-
Leandro over 4 yearsHow do you set that?
-
solimant about 4 yearsCouldn't improve answer since edit queue is full (?!). Added an answer with steps and screenshot to elaborate.
-
jwenting almost 3 yearsnote that this screen tends to change once in a while, for example in the 2021 version of IntelliJ the code coverage options are now below the configuration options, not in a separate tab.
-
user9712582 about 2 yearsAppears to be the same answer as henry sneed's, though shorter without screenshots. (Both might benefit from a version number)