This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 157946

Summary: Enable inline code coverage for maven projects
Product: projects Reporter: bradmac <bradmac>
Component: MavenAssignee: Jesse Glick <jglick>
Status: RESOLVED FIXED    
Severity: blocker CC: emononen, jglick, mkleint, nebelmann, pjiricka, tprochazka, vernons
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
URL: http://wiki.netbeans.org/MavenCodeCoverage
Issue Type: ENHANCEMENT Exception Reporter:

Description bradmac 2009-02-04 22:59:34 UTC
The maven project support in netbeans is fantastic, and much better then the competition. However, this benefit is
severely diminished because code coverage data can't be displayed inline in the editor for maven projects.

Please extend the maven code project support to work with the code coverage plugin.
Comment 1 Milos Kleint 2009-02-05 05:06:30 UTC
this is something to be filed against the code coverage plugin. I'm not aware of any API that maven support could
implement to get code coverage.

what coverage plugin are we talking about?
Comment 2 Milos Kleint 2009-03-23 15:47:35 UTC
reassigning.
Comment 3 bradmac 2009-03-23 20:16:57 UTC
Sorry for not replying sooner.

In my case, the maven projects uses cobertura. I can use this data by running the cobertura:cobertura goal, then opening
the generated html files to see which classes need their coverage improved. My colleagues who use another IDE have
coverage data presented in the IDE directly in the java view. 

There are plugins available for netbeans projects which provide this functionality (http://codecoverage.netbeans.org/)
however this doesnt appear to work in maven projects

Ideally i would like maven projects to be compatible with all plugins that work with standard projects, but code
coverage is of particular concern given the industry drive to high levels of code coverage.
Comment 4 Nowaker 2010-07-16 00:53:39 UTC
There is a tutorial how to hack coverage plugin to work with Maven projects. http://sharebear.co.uk/blog/2009/01/21/code-coverage-maven-projects-netbeans/
Comment 5 Jesse Glick 2010-11-12 21:32:17 UTC
http://wiki.netbeans.org/RubyCodeCoverage discusses comparable support for Ruby projects, using the gsf.codecoverage API. Probably this could be implemented for Java source files in Maven projects. Not sure what exactly is needed, since I cannot yet get it to work reliably in Ruby projects.
Comment 6 Jesse Glick 2010-11-12 23:54:06 UTC
I'm experimenting with a Maven provider based on the Cobertura plugin. Past feature freeze for 7.0 so it can't go into the standard distribution, but could be put on Beta AU perhaps.
Comment 7 bradmac 2010-11-13 01:03:18 UTC
Great news! Let me know if you want a beta tester
Comment 8 Milos Kleint 2010-11-13 06:41:15 UTC
you might be interested in jacoco - http://www.eclemma.org/jacoco/trunk/

 haven't used it, just haveve seen it demoed at Eclipsecon in March. The great advantage of jacoco compared to other tools is that it doesn't require additional compilation cycle. it's just a java agent that gets set for the executed tests..
Comment 9 Quality Engineering 2010-11-14 06:22:33 UTC
Integrated into 'main-golden', will be available in build *201011140001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/ea8e120adeb2
User: Jesse Glick <jglick@netbeans.org>
Log: Starting work on #157946: Maven code coverage.
Comment 10 Petr Jiricka 2010-11-14 19:36:04 UTC
This is great news! Note that code coverage is also implemented for PHP, see http://blogs.sun.com/netbeansphp/entry/code_coverage_for_php_why
Comment 11 Jesse Glick 2010-11-16 00:48:08 UTC
Cobertura support should be on dev AU when core-main #e14bbcdb5ce3 propagates.

The "Test" button does not work - limitation of API - but "All Tests" does. So for now you cannot refresh coverage on a single class, only the whole module.

For now you have to add the Cobertura plugin to your project manually (the module will not set it up for you); suffices to be declared in plugin section, or added as a 2.x-style or 3.x-style reporting plugin. The generic UI has a checkbox to disable coverage but this does nothing for now.

There are probably some other rough spots, but this may be enough to get started with.

JaCoCo sounds interesting. Not sure if it is easy for a Maven plugin to tell Surefire to use an extra agent param, though.
Comment 12 Jesse Glick 2010-11-16 17:04:41 UTC
It is on the dev update center for anyone who wants to test it. Will only work in 7.0 dev builds (after the Beta).
Comment 13 vernons 2010-11-22 10:13:13 UTC
Can more explicit instructions for how to use this be provided? I couldn't figure out how to get it to work.
Comment 14 Jesse Glick 2010-11-23 00:43:13 UTC
(In reply to comment #13)
> I couldn't figure out how to get it to work.

Did you install the plugin from dev AU? Do you have the Cobertura plugin configured on your project? Is there a Code Coverage menu item on your project's context menu? Did you open the report, Run All Tests, and did results appear? Does target/site/cobertura/coverage.xml exist with plausible contents?
Comment 15 vernons 2010-11-23 01:50:04 UTC
Environment: NetBeans Dev 201011210001 - Mac OS X 10.6.5 - Java 1.6.0_22

Did you install the plugin from dev AU? 
Yes (Maven Test Coverage - also restarted NetBeans after installing the plug-in)

Do you have the Cobertura plugin configured on your project?
Yes (maven-cobertura-plugin [1.4] added to Test Dependencies - Also re-started NetBeans after configuring this)

Is there a Code Coverage menu item on your project's context menu? 
No

Did you open the report, Run All Tests, and did results appear? 
N/A

Does target/site/cobertura/coverage.xml exist with plausible contents?
N/A
Comment 16 Jesse Glick 2010-11-23 18:41:48 UTC
(In reply to comment #15)
> Yes (maven-cobertura-plugin [1.4] added to Test Dependencies

Ah. This doesn't make any sense; you are not compiling your tests against a Maven plugin! So don't add it to the dependencies section. The IDE will look in the build plugins section (although this plugin defines no default executions, so defining it here is probably uncommon), or in the reporting plugins section (using either Maven 2.x or 3.x syntax). If it can't find the plugin mentioned in any of these places, the submenu will be suppressed.
Comment 17 vernons 2010-11-24 07:29:22 UTC
OK. I edited the POM to include cobertura and the cobertura-maven-plugin and I'm not able to see the context menu, select the Show Reports... and use the Run All Tests to generate test coverage. I'm often encountering Null Pointer Exception, Array Out of Index and some other errors when using it. Not sure if that's related to not having all of the required plug-ins included or there are still some bugs to be worked out. I'm submitting reports as they occur.
Comment 18 Jesse Glick 2010-11-24 16:03:43 UTC
(In reply to comment #17)
> I'm often encountering Null Pointer
> Exception, Array Out of Index and some other errors when using it. Not sure if
> that's related

Might be completely unrelated to coverage support, hard to say. Just use the exception reporter every time and they will get dealt with.
Comment 19 Jesse Glick 2010-12-06 19:31:51 UTC
Petr helpfully wrote up a little tutorial!
Comment 20 vernons 2010-12-07 00:31:30 UTC
Thanks Petr!