JaCoCo, Maven, and NetBeans

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.

Now, let's say you want to move from doing code coverage for your Java code to doing it for your JavaScript. That's what the Karma Istanbul project is all about, which is integrated in exactly the same way, minus the Maven, into NetBeans IDE as the above, as described in Karma Istanbul Code Coverage in NetBeans IDE.

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
4
5
11
12
26
27
28
29
30
  
       
Today