[ 
http://jira.codehaus.org/browse/MCOBERTURA-86?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=240913#action_240913
 ] 

ludovic commented on MCOBERTURA-86:
-----------------------------------

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.

{code:xml}
<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>
{code} 

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.

{code:xml}
<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>
{code} 

What do you think ?


> no coverage reported for integration-test
> -----------------------------------------
>
>                 Key: MCOBERTURA-86
>                 URL: http://jira.codehaus.org/browse/MCOBERTURA-86
>             Project: Maven 2.x Cobertura Plugin
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: Windows XP, maven 2.0.8
>            Reporter: Jean-Francois Poilpret
>         Attachments: 
> cobertura-maven-plugin_check-only-and-report-only-mojos_with-IT.patch, 
> cobertura-maven-plugin_check-only-and-report-only-mojos_with-IT_for-2.5-SNAPSHOT.patch,
>  cobertura-maven-plugin_check-only-mojo.patch, 
> CoberturaIntegrationReportMojo.patch, CoberturaReportOnlyMojo.patch
>
>
> 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?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to