JaCoCo, Maven, and NetBeans
By Geertjan-Oracle on Sep 04, 2014
I met Marc Hoffmann, the author of the JaCoCo project, at JCrete. I probably asked him the dumbest question ever, so embarrassing that I can only document it here within braces. ("What does 'JaCoCo' actually stand for?"). Putting that awkward moment aside can best be done by showing how awesome JaCoCo support is in NetBeans IDE.
Simply open your POM and stick the below into it:
<build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.1.201405082137</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
By the way, notice how helpful code completion is in the POM:
And not only for the version number:
Done the above? Good. While thinking that you've added some tags to your POM file... what you have also done is caused the following menu item to be made visible when you right-click your Maven project:
That "Code Coverage" menu that you see above will only be visible once you have added the JaCoCo plugin to the POM of your project, i.e., by sticking the XML shown about into your POM. Choose "Show Report" above and then the window below opens (click to enlarge it below). Then run your tests, which you can do directly from the window below, and see the results, i.e., the percentage of your code that's covered by your tests:
Next, open your files, and notice the green/red in your code (click to enlarge the image below), as well as the editor bar, if you have "Show Editor Bar" selected.
That's what's cool about having an integrated development environment, i.e., you can transfer your skills from one technology to the next without changing your toolset.