anthomaxcool
anthomaxcool

Reputation: 359

Test coverage missing in Netbeans 8.1?

I downloaded recently Netbeans 8.1 here

I chose second option: "Java EE".

But I can't find how to run test coverage for my unit tests. I have this menu:

enter image description here

It's a Maven Web Application.

When I go to Tools -> Plugins and search for "coverage", I have this:

enter image description here

I installed it and restarted the IDE, I saw it was installing the plugin but there's no change in my menu. If I search "coverage" in the Installed plugins, nothing shows up else than the one I just installed... I thought Netbeans had it implemented? I also thought Netbeans has the Maven test coverage as well...

I read that the plugin I installed (TikiOne JaCoCoverage) is just an extension of the already existing Netbeans Test Coverage.. so that would explain why I can't see it.

How can I enable test coverage?

Thanks.

Upvotes: 6

Views: 9024

Answers (3)

gpap
gpap

Reputation: 2864

Keep in mind that after you install the plugin and add this info in your pom, you might be able to see the option code coverage when you right click in a package. However, as javaeeeee's answer says, you SHOULD BUILD your project again in order to see the actual coverage.

Upvotes: 0

javaeeeee
javaeeeee

Reputation: 681

you should add the JaCoCo plugin into <plugins> section of your pom.xml file.

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</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>

After you build the project, the menu item for Code Coverage menu item appears when you right-click the project.

Netbeans Code Coverage Menu

Finally, you can select Show Report from the menu. Everything is described here.

Upvotes: 19

Hugo G
Hugo G

Reputation: 16496

This is unfortunately little documented, but for me the menu entries appeared when I added the JaCoCo Maven plugin by hand:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <rules><!-- implementation is needed only for Maven 2 -->
                    <rule implementation="org.jacoco.maven.RuleConfiguration">
                        <element>BUNDLE</element>
                        <limits><!-- implementation is needed only for Maven 2 -->
                            <limit implementation="org.jacoco.report.check.Limit">
                                <counter>COMPLEXITY</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.01</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

The maven goal verify runs the coverage report. You'll also have the window for coverage as mentioned in the official docs.

Unfortunately the plugin or the integration seems a little buggy, since you can either run the tests and see its results in the Test Results NB window, OR see the coverage... there seems to be two ways of running tests and I haven't found a way to do both at the same time yet.

Upvotes: 3

Related Questions