Maven 2.x Cobertura Plugin

no coverage reported for integration-test

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 2.2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP, maven 2.0.8
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    5

Description

In my project, I have both unit tests ("test" phase) and integration tests ("integration-test" phase).
So far I could manage configuring maven-surefire-plugin and maven-surefire-report-plugin to execute both tests correctly and also generate 2 different reports.
Then I have added cobertura-maven-plugin to the reporting in order to get coverage but unfortunately only unit tests have their coverage reported (I know it because I have some classes which are only integration tested but are reported as 0% covered).
After trying to find information on the mailing lists, on the web and other existing resources, I could not find any hint on how to make this work.
It looks like cobertura-maven-plugin, by its current design, will never run integration-test to collect coverage, it seems to stop at the "test" phase.

Thus whenever a POM project has integration tests and uses cobertura-maven-plugin for coverage report, the generated reports are wrong, which is very misleading.

Actually, I was surprised not to find this issue already in JIRA.

Is there a chance this gets fixed soon? Or is there a usable workaround for this problem (besides switching to clover which I am not sure it would work better ) Did someone succeed in patching cobertura-maven-plugin to get the correct behavior?

Issue Links

Activity

Hide
Kalle Korhonen added a comment -

The documentation for cobertura:cobertura flat out says that it runs the "test" phase prior to executing itself, so I assume this currently cannot be configured. There's of course much more complicated cases that people use the integration-test phase for, but for a lot of projects, it'd be enough if you could configure Cobertura to at least include or run integration-test phase instead. Email thread at http://www.mail-archive.com/users@maven.apache.org/msg78743.html.

Show
Kalle Korhonen added a comment - The documentation for cobertura:cobertura flat out says that it runs the "test" phase prior to executing itself, so I assume this currently cannot be configured. There's of course much more complicated cases that people use the integration-test phase for, but for a lot of projects, it'd be enough if you could configure Cobertura to at least include or run integration-test phase instead. Email thread at http://www.mail-archive.com/users@maven.apache.org/msg78743.html.
Hide
Damien Lecan added a comment -

Someone to work on this ?
Thanks

Show
Damien Lecan added a comment - Someone to work on this ? Thanks
Hide
Stevo Slavic added a comment -

Here's a patch, with new cobertura:cobertura-integration report mojo, which extends existing cobertura report mojo but instead of test phase executes verify phase to have pre-integration-test, integration-test, and post-integration-test phases to execute as well. To use it one should define in pom reporting section something like this:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>

This has been tested only on a trivial example project, and appears to be working well. I'm absolute beginner when it comes to mojo development, so this patch should be treated in that light, just as an suggestion on how this issue could be resolved.

The second patch adds one more new cobertura:report-only mojo, which executes only validate phase. Idea is that one should be able to use it together with cobertura:clean cobertura:instrument mojos, for fine-grained control over instrumentation process.

Show
Stevo Slavic added a comment - Here's a patch, with new cobertura:cobertura-integration report mojo, which extends existing cobertura report mojo but instead of test phase executes verify phase to have pre-integration-test, integration-test, and post-integration-test phases to execute as well. To use it one should define in pom reporting section something like this: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.3-SNAPSHOT</version> <reportSets> <reportSet> <reports> <report>cobertura-integration</report> </reports> </reportSet> </reportSets> </plugin> This has been tested only on a trivial example project, and appears to be working well. I'm absolute beginner when it comes to mojo development, so this patch should be treated in that light, just as an suggestion on how this issue could be resolved. The second patch adds one more new cobertura:report-only mojo, which executes only validate phase. Idea is that one should be able to use it together with cobertura:clean cobertura:instrument mojos, for fine-grained control over instrumentation process.
Hide
Stevo Slavic added a comment -

I've tested and can confirm that both new Mojo's work well with relatively big multi-module projects.

Can someone else please try too?

Is it possible to get at least report-only mojo included in 2.3? With it, and with existing clean and instrument mojos, one can have more complete control over what and when gets instrumented, run tests and then get a coverage report only without rerunning of tests just for report. cobertura-integration mojo is not needed, but can be useful for simpler use cases, where with less configuration one can get coverage data for tests run in integration-test phase along with coverage data for tests in test phase.

Show
Stevo Slavic added a comment - I've tested and can confirm that both new Mojo's work well with relatively big multi-module projects. Can someone else please try too? Is it possible to get at least report-only mojo included in 2.3? With it, and with existing clean and instrument mojos, one can have more complete control over what and when gets instrumented, run tests and then get a coverage report only without rerunning of tests just for report. cobertura-integration mojo is not needed, but can be useful for simpler use cases, where with less configuration one can get coverage data for tests run in integration-test phase along with coverage data for tests in test phase.
Hide
Tom Vaughan added a comment -

Hi,

How/where do I go to get the 2.3-SNAPSHOT release? I don't see it on ibiblio, but I'd love to get that version to help test this function.

Thanks,
Tom

Show
Tom Vaughan added a comment - Hi, How/where do I go to get the 2.3-SNAPSHOT release? I don't see it on ibiblio, but I'd love to get that version to help test this function. Thanks, Tom
Hide
Simon Brandhof added a comment -

Snapshot is deployed but I'm not sure that this patch has been applied.

Show
Simon Brandhof added a comment - Snapshot is deployed but I'm not sure that this patch has been applied.
Hide
Stevo Slavic added a comment -

To test the cobertura:report-only mojo patch one can check out latest cobertura-maven-plugin sources from http://svn.codehaus.org/mojo/ under trunk/mojo/cobertura-maven-plugin, apply the patch, install the plugin snapshot in to your local repository, and then use it from your maven project.

Show
Stevo Slavic added a comment - To test the cobertura:report-only mojo patch one can check out latest cobertura-maven-plugin sources from http://svn.codehaus.org/mojo/ under trunk/mojo/cobertura-maven-plugin, apply the patch, install the plugin snapshot in to your local repository, and then use it from your maven project.
Hide
Fabrice Daugan added a comment -

Hi Stevo,
I've patched the 2.3 snapshot with your work, and it works on big pom tree (parent/module) configuration.
But how did you solved the "classesDirectory " problem when using : surefire+selenium+cobertura when executing test, deployment, it and site into an unique maven execution ?
Removing the "readOnly" flag from the war plugin slove partially the problem, but i think there is a much simplier solution to run correctly cobertura ....
Can you attach a pom sample and the associated maven command line you use please?

Thanks

Show
Fabrice Daugan added a comment - Hi Stevo, I've patched the 2.3 snapshot with your work, and it works on big pom tree (parent/module) configuration. But how did you solved the "classesDirectory " problem when using : surefire+selenium+cobertura when executing test, deployment, it and site into an unique maven execution ? Removing the "readOnly" flag from the war plugin slove partially the problem, but i think there is a much simplier solution to run correctly cobertura .... Can you attach a pom sample and the associated maven command line you use please? Thanks
Hide
Fabrice Daugan added a comment -

Why this patch has not been released to 2.3 version?
It works very well on simple and complexe configuration.

Show
Fabrice Daugan added a comment - Why this patch has not been released to 2.3 version? It works very well on simple and complexe configuration.
Hide
Stevo Slavic added a comment -

Wish "report-only" mojo was included in 2.3, hopefully it will get included in 2.4, together with this new one, "check-only" mojo (see attached cobertura-maven-plugin_check-only-mojo.patch). Current cobertura:check mojo is heavy, it includes running tests, so if one wants to run tests (e.g. with surefire), auto check coverage (cobertura:check), and get a coverage report in a site (using cobertura:cobertura), tests get run at least 3 times - having tests run twice (once on non instrumented code to check if code is ok, and once on instrumented code to get coverage) takes time but it's understandable, while having them run 3 times is way too much. Point is that cobertura maven plugin should be able to reuse coverage data for both check and for report generation tasks. With report-only and check-only this is feasible - with all these mojos at hand one could:

1) cobertura:clean
2) run the tests on non instrumented code and only if they pass execute...
3) cobertura:instrument
4) run the tests on instrumented code (this would generate coverage data)
5) cobertura:check-only, to check if coverage requirements are met, and only if they are execute...
6) cobertura:report-only, as part of project site generation

Show
Stevo Slavic added a comment - Wish "report-only" mojo was included in 2.3, hopefully it will get included in 2.4, together with this new one, "check-only" mojo (see attached cobertura-maven-plugin_check-only-mojo.patch). Current cobertura:check mojo is heavy, it includes running tests, so if one wants to run tests (e.g. with surefire), auto check coverage (cobertura:check), and get a coverage report in a site (using cobertura:cobertura), tests get run at least 3 times - having tests run twice (once on non instrumented code to check if code is ok, and once on instrumented code to get coverage) takes time but it's understandable, while having them run 3 times is way too much. Point is that cobertura maven plugin should be able to reuse coverage data for both check and for report generation tasks. With report-only and check-only this is feasible - with all these mojos at hand one could: 1) cobertura:clean 2) run the tests on non instrumented code and only if they pass execute... 3) cobertura:instrument 4) run the tests on instrumented code (this would generate coverage data) 5) cobertura:check-only, to check if coverage requirements are met, and only if they are execute... 6) cobertura:report-only, as part of project site generation
Hide
Stevo Slavic added a comment -

CoberturaIntegrationReportMojo.patch can be deleted/ignored, report-only mojo is enough.

Show
Stevo Slavic added a comment - CoberturaIntegrationReportMojo.patch can be deleted/ignored, report-only mojo is enough.
Hide
Stevo Slavic added a comment -

Attaching patch with updated check-only and report-only mojos (cobertura-maven-plugin_check-only-and-report-only-mojos_with-IT), now with their integration test. Previous patches can be deleted/ignored.

Show
Stevo Slavic added a comment - Attaching patch with updated check-only and report-only mojos (cobertura-maven-plugin_check-only-and-report-only-mojos_with-IT), now with their integration test. Previous patches can be deleted/ignored.
Hide
Stephen Connolly added a comment -

Updating the issue to reflect that there is now a patch with integration test case

Show
Stephen Connolly added a comment - Updating the issue to reflect that there is now a patch with integration test case
Hide
Michael Spaulding added a comment -

I'm wondering if there is a danger in the new approach of running the individual steps. Let's say I attach the various goals to my default lifecycle. Isn't there a danger that a package step will package up the instrumented classes because the instrument goal does the following:

// Set the instrumented classes to be the new output directory (for other plugins to pick up)
project.getBuild().setOutputDirectory( instrumentedDirectory.getPath() );
System.setProperty( "project.build.outputDirectory", instrumentedDirectory.getPath() );

Show
Michael Spaulding added a comment - I'm wondering if there is a danger in the new approach of running the individual steps. Let's say I attach the various goals to my default lifecycle. Isn't there a danger that a package step will package up the instrumented classes because the instrument goal does the following: // Set the instrumented classes to be the new output directory (for other plugins to pick up) project.getBuild().setOutputDirectory( instrumentedDirectory.getPath() ); System.setProperty( "project.build.outputDirectory", instrumentedDirectory.getPath() );
Hide
Candy Chiu added a comment -

I tried the new cobertura:cobertura-integration mojo in 2.3-SNAPSHOT downloaded from http://snapshots.repository.codehaus.org. It didn't work on my project. All integration tests were skipped.

Show
Candy Chiu added a comment - I tried the new cobertura:cobertura-integration mojo in 2.3-SNAPSHOT downloaded from http://snapshots.repository.codehaus.org. It didn't work on my project. All integration tests were skipped.
Hide
Nikhil Almeida added a comment -

Hi, I wanted to be able to run my integration tests with cobertura. I added the http://snapshots.repository.codehaus.org to the repository and did an mvn clean. It then downloaded the jars.
I then ran mvn cobertura:cobertura-integration command but got an error that said the new mojo was not found.

Pasted below is the our put of the mvn clean command that shouws the jars being downloaded.

[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\Users\abc\workspace\restapi\target
[INFO] [cobertura:clean {execution: default}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Apr 22 10:43:14 EDT 2010
[INFO] Final Memory: 9M/247M
[INFO] ------------------------------------------------------------------------
C:\Users\abc\ workspace\restapi>mvn clean
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building restapi
[INFO] task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] snapshot org.codehaus.mojo:cobertura-maven-plugin:2.3-SNAPSHOT: checking
for updates from org.codehaus.mojo
[INFO] snapshot org.codehaus.mojo:cobertura-maven-plugin:2.3-SNAPSHOT: checking
for updates from nikhil
Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/cobertur
a-maven-plugin/2.3-SNAPSHOT/cobertura-maven-plugin-2.3-20090629.120157-3.pom
5K downloaded (cobertura-maven-plugin-2.3-20090629.120157-3.pom)
Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/mojo/16/
mojo-16.pom
[INFO] Unable to find resource 'org.codehaus.mojo:mojo:pom:16' in repository org
.codehaus.mojo (http://snapshots.repository.codehaus.org)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo/16/mojo-16.pom

Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/cobertur
a-maven-plugin/2.3-SNAPSHOT/cobertura-maven-plugin-2.3-20090629.120157-3.jar
31K downloaded (cobertura-maven-plugin-2.3-20090629.120157-3.jar)
Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/mojo-par
ent/23/mojo-parent-23.pom
[INFO] Unable to find resource 'org.codehaus.mojo:mojo-parent:pom:23' in reposit
ory org.codehaus.mojo (http://snapshots.repository.codehaus.org)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/23/mojo
-parent-23.pom

[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\Users\abc\workspace\restapi\target
[INFO] [cobertura:clean {execution: default}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Apr 22 10:44:23 EDT 2010
[INFO] Final Memory: 9M/247M
[INFO] ------------------------------------------------------------------------

And here the mvn cobertura:cobertura-integration command being run

C:\Users\abc\workspace\restapi>mvn cobertura:cobertura-integration

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Required goal not found: cobertura:cobertura-integration in org.codehaus.
mojo:cobertura-maven-plugin:2.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Apr 22 11:13:27 EDT 2010
[INFO] Final Memory: 3M/247M
[INFO] ------------------------------------------------------------------------
C:\Users\abc\workspace\restapi>

Show
Nikhil Almeida added a comment - Hi, I wanted to be able to run my integration tests with cobertura. I added the http://snapshots.repository.codehaus.org to the repository and did an mvn clean. It then downloaded the jars. I then ran mvn cobertura:cobertura-integration command but got an error that said the new mojo was not found. Pasted below is the our put of the mvn clean command that shouws the jars being downloaded. [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory C:\Users\abc\workspace\restapi\target [INFO] [cobertura:clean {execution: default}] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Thu Apr 22 10:43:14 EDT 2010 [INFO] Final Memory: 9M/247M [INFO] ------------------------------------------------------------------------ C:\Users\abc\ workspace\restapi>mvn clean [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building restapi [INFO] task-segment: [clean] [INFO] ------------------------------------------------------------------------ [INFO] snapshot org.codehaus.mojo:cobertura-maven-plugin:2.3-SNAPSHOT: checking for updates from org.codehaus.mojo [INFO] snapshot org.codehaus.mojo:cobertura-maven-plugin:2.3-SNAPSHOT: checking for updates from nikhil Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/cobertur a-maven-plugin/2.3-SNAPSHOT/cobertura-maven-plugin-2.3-20090629.120157-3.pom 5K downloaded (cobertura-maven-plugin-2.3-20090629.120157-3.pom) Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/mojo/16/ mojo-16.pom [INFO] Unable to find resource 'org.codehaus.mojo:mojo:pom:16' in repository org .codehaus.mojo (http://snapshots.repository.codehaus.org) Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo/16/mojo-16.pom Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/cobertur a-maven-plugin/2.3-SNAPSHOT/cobertura-maven-plugin-2.3-20090629.120157-3.jar 31K downloaded (cobertura-maven-plugin-2.3-20090629.120157-3.jar) Downloading: http://snapshots.repository.codehaus.org/org/codehaus/mojo/mojo-par ent/23/mojo-parent-23.pom [INFO] Unable to find resource 'org.codehaus.mojo:mojo-parent:pom:23' in reposit ory org.codehaus.mojo (http://snapshots.repository.codehaus.org) Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/23/mojo -parent-23.pom [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory C:\Users\abc\workspace\restapi\target [INFO] [cobertura:clean {execution: default}] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Thu Apr 22 10:44:23 EDT 2010 [INFO] Final Memory: 9M/247M [INFO] ------------------------------------------------------------------------ And here the mvn cobertura:cobertura-integration command being run C:\Users\abc\workspace\restapi>mvn cobertura:cobertura-integration [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Required goal not found: cobertura:cobertura-integration in org.codehaus. mojo:cobertura-maven-plugin:2.3-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Thu Apr 22 11:13:27 EDT 2010 [INFO] Final Memory: 3M/247M [INFO] ------------------------------------------------------------------------ C:\Users\abc\workspace\restapi>
Hide
Robert Scholte added a comment -

@Nikhil Almeida
Like the logs already tell you: the cobertura-integration goal doesn't exist. Not in cobertura-maven-plugin-2.3 or in the current trunk.
Although there are a lot of votes, this patch hasn't been added to the plugin yet.

Show
Robert Scholte added a comment - @Nikhil Almeida Like the logs already tell you: the cobertura-integration goal doesn't exist. Not in cobertura-maven-plugin-2.3 or in the current trunk. Although there are a lot of votes, this patch hasn't been added to the plugin yet.
Hide
Benoit Xhenseval added a comment -

Was there any reason why this patch was not applied to the new release done on April 25? Is any developer looking into this? Please, pretty please...

Show
Benoit Xhenseval added a comment - Was there any reason why this patch was not applied to the new release done on April 25? Is any developer looking into this? Please, pretty please...
Hide
nicola d'elia added a comment -

please release it, i need it too!

Show
nicola d'elia added a comment - please release it, i need it too!
Hide
Conny Kreyssel added a comment -

Can anyone apply the patch and release it - in 2.5?

Show
Conny Kreyssel added a comment - Can anyone apply the patch and release it - in 2.5?
Hide
Navjeet added a comment -

We are using version 2.4 and it seems to run integration tests but as unit tests (our integration tests are cactus based). So is it confirmed that v 2.4 of maven plugin won't run integration tests?

Show
Navjeet added a comment - We are using version 2.4 and it seems to run integration tests but as unit tests (our integration tests are cactus based). So is it confirmed that v 2.4 of maven plugin won't run integration tests?
Hide
Rafael Mahnovetsky added a comment -

I applied your patch and now I can run a cobertura report after integration test .. nice one!

I hope your patches get applied in the next release.

At least we can now have a choice if we want to include integration tests into our code coverage or not.

Show
Rafael Mahnovetsky added a comment - I applied your patch and now I can run a cobertura report after integration test .. nice one! I hope your patches get applied in the next release. At least we can now have a choice if we want to include integration tests into our code coverage or not.
Hide
Martijn Verburg added a comment -

+1 On wishing to see this patch applied - it would tie in nicely with our Hudson reporting

Show
Martijn Verburg added a comment - +1 On wishing to see this patch applied - it would tie in nicely with our Hudson reporting
Hide
ludovic added a comment -

This issue is opened since 01/Mar/08. This is more than 2 years. There is a simple patch that works and it just adds two goals, so the plugin is backward compatible. Why this take so long to do ? May we have a response about when we can have this done or not. Because I'm about to do a fork of this plugin on google code with the possibility to do integration test coverage on war application which is really cool to see functional test coverage. Sorry for the tone, I really like your work
I attach the updated patch which work on latest 2.5-SNAPSHOT.

Show
ludovic added a comment - This issue is opened since 01/Mar/08. This is more than 2 years. There is a simple patch that works and it just adds two goals, so the plugin is backward compatible. Why this take so long to do ? May we have a response about when we can have this done or not. Because I'm about to do a fork of this plugin on google code with the possibility to do integration test coverage on war application which is really cool to see functional test coverage. Sorry for the tone, I really like your work I attach the updated patch which work on latest 2.5-SNAPSHOT.
Hide
Robert Scholte added a comment -

I think the problem with this issue is that it only covers half of the problem. It will only work for classes executed by the m-failsafe-p, because it can use these instrumented classes. But you might want to do an integration-test on the generated jar/war/.. and that's not possible.
You don't want the (main) artifact to be instrumented, but you might want to have an instrumented version as well (with cobertura classifier) and use that one to do the integration-test.

To cover the first type of integration-tests I'll review the patches. I don't think it would harm to add a report-only goal to the plugin.

Show
Robert Scholte added a comment - I think the problem with this issue is that it only covers half of the problem. It will only work for classes executed by the m-failsafe-p, because it can use these instrumented classes. But you might want to do an integration-test on the generated jar/war/.. and that's not possible. You don't want the (main) artifact to be instrumented, but you might want to have an instrumented version as well (with cobertura classifier) and use that one to do the integration-test. To cover the first type of integration-tests I'll review the patches. I don't think it would harm to add a report-only goal to the plugin.
Hide
ludovic added a comment -

I found a small trick that make integration-test works on instrumented jar/war/...

Obviously I use a maven profile that I only trigger during dev and on my ci server.
If my war application does not depend on other artifact, the code is quite simple. I use IT test (which are now understood by husdon ci) and I load my war (multiple times) using jetty during these tests. At the end, the cobertura results are flushed.

<profile>
    <id>it-coverage</id>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats> 
                    <check>
                        <haltOnFailure>false</haltOnFailure>
                    </check>
                    <instrumentation>
                        <excludes>
                            <exclude>**/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <id>cobertura-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-check-only</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check-only</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
</profile>

But when you have dependencies you want the coverage to go through. so I use a trick. I exclude my dependencies from the war build and instead I unpack the dependencies sources and attach them to the build. Maven compile and instrument these classes and we have the coverage we want

And this is only possible with the patch.

<profile>
    <id>it-coverage</id>
    
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-dependencies-src</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <classifier>sources</classifier>
                            <includeGroupIds>com.example</includeGroupIds>
                             <outputDirectory>${project.build.directory}/generated-sources/it-dependencies</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-it-dep-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/it-dependencies</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats> 
                    <check>
                        <haltOnFailure>false</haltOnFailure>
                    </check>
                    <instrumentation>
                        <excludes>
                            <exclude>**/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <id>cobertura-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-check-only</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check-only</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archiveClasses>false</archiveClasses>
                    <packagingExcludes>WEB-INF/lib/example-*.jar</packagingExcludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
</profile>

What do you think ?

Show
ludovic added a comment - I found a small trick that make integration-test works on instrumented jar/war/... Obviously I use a maven profile that I only trigger during dev and on my ci server. If my war application does not depend on other artifact, the code is quite simple. I use IT test (which are now understood by husdon ci) and I load my war (multiple times) using jetty during these tests. At the end, the cobertura results are flushed.
<profile>
    <id>it-coverage</id>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats> 
                    <check>
                        <haltOnFailure>false</haltOnFailure>
                    </check>
                    <instrumentation>
                        <excludes>
                            <exclude>**/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <id>cobertura-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-check-only</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check-only</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
</profile>
But when you have dependencies you want the coverage to go through. so I use a trick. I exclude my dependencies from the war build and instead I unpack the dependencies sources and attach them to the build. Maven compile and instrument these classes and we have the coverage we want And this is only possible with the patch.
<profile>
    <id>it-coverage</id>
    
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-dependencies-src</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <classifier>sources</classifier>
                            <includeGroupIds>com.example</includeGroupIds>
                             <outputDirectory>${project.build.directory}/generated-sources/it-dependencies</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-it-dep-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/it-dependencies</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats> 
                    <check>
                        <haltOnFailure>false</haltOnFailure>
                    </check>
                    <instrumentation>
                        <excludes>
                            <exclude>**/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <id>cobertura-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-instrument</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>cobertura-check-only</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check-only</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archiveClasses>false</archiveClasses>
                    <packagingExcludes>WEB-INF/lib/example-*.jar</packagingExcludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
</profile>
What do you think ?
Hide
Robert Scholte added a comment -

Maybe MCOBERTURA-114 could help here

Show
Robert Scholte added a comment - Maybe MCOBERTURA-114 could help here
Hide
Robert Scholte added a comment -

After reviewing this issue, I don't think the check-only/report-only is the right solution.
The cobertura-lifecycle has to be extended, and I think it should look something like this:

Before entering the test phase, the java-classes need to be instrumented for test
Before entering the integration-test phase, java-classes need to be instrumented for integration-test.
Now they both have their own .ser file, and during verify all these should be checked and eventually reported.
I think this would result in less configuration and no need to misuse a report-only goal.

Show
Robert Scholte added a comment - After reviewing this issue, I don't think the check-only/report-only is the right solution. The cobertura-lifecycle has to be extended, and I think it should look something like this: Before entering the test phase, the java-classes need to be instrumented for test Before entering the integration-test phase, java-classes need to be instrumented for integration-test. Now they both have their own .ser file, and during verify all these should be checked and eventually reported. I think this would result in less configuration and no need to misuse a report-only goal.
Hide
ludovic added a comment -

I agree. So that way we can have two coverage reports, one for unit tests and the other for integration tests. And so, we can invoke mvn site and got results without running verify goal first, which is required with the patch.

Show
ludovic added a comment - I agree. So that way we can have two coverage reports, one for unit tests and the other for integration tests. And so, we can invoke mvn site and got results without running verify goal first, which is required with the patch.
Hide
Gábor Lipták added a comment - - edited
Show
Gábor Lipták added a comment - - edited A reasonable alternative for integration testing coverage is here: http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+Sonar+(Sonar)&utm_content=Google+Reader It works fine for me.
Hide
Harald Brabenetz added a comment -

I use the following workaround:

<profile>
  <!-- Build with IntegrationTestcoverage => instrument classes with cobertura before integrationtests starts. -->
  <id>buildWithIntegrationTestCoverage</id>
  <activation>
    <property>
      <name>buildWithIntegrationTestCoverage</name>
      <value>true</value>
    </property>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>instrument-classes</id>
            <phase>package</phase>
            <goals>
              <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    
      <!-- Add cobertura as dependency to the jetty-plugin (required for instrumented classes) -->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.3</version>
            <type>jar</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</profile>

And then i start the site-generation with:

mvn clean install site -DbuildWithIntegrationTestCoverage=true
Show
Harald Brabenetz added a comment - I use the following workaround:
<profile>
  <!-- Build with IntegrationTestcoverage => instrument classes with cobertura before integrationtests starts. -->
  <id>buildWithIntegrationTestCoverage</id>
  <activation>
    <property>
      <name>buildWithIntegrationTestCoverage</name>
      <value>true</value>
    </property>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>instrument-classes</id>
            <phase>package</phase>
            <goals>
              <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    
      <!-- Add cobertura as dependency to the jetty-plugin (required for instrumented classes) -->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.3</version>
            <type>jar</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</profile>
And then i start the site-generation with:
mvn clean install site -DbuildWithIntegrationTestCoverage=true

People

Vote (61)
Watch (50)

Dates

  • Created:
    Updated: