How to generate Cobertura Code Coverage Report using Maven from Hudson
Asked Answered
M

4

25

In my project I need to create Cobertura Code Coverage report from Hudson using maven build.
In Hudson I have added the Cobertura Code Coverage plugin.
I need the complete modification steps of pom.xml.

Maxantia answered 5/1, 2010 at 12:40 Comment(1)
Beware of the Java 7 incompatibility! A possible [solution is shown here][1]. [1]: #7011165Museum
B
33

Did you try to add this to your pom.xml in the reporting section?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <configuration>
       <formats>
           <format>html</format>
           <format>xml</format>
       </formats>
    </configuration>
</plugin>

Complete configuration steps can be found here.

Brentwood answered 5/1, 2010 at 12:50 Comment(2)
I have added configuration under section 'Execute cobertura only from hudson using profiles' available at 'wiki.hudson-ci.org/display/HUDSON/Cobertura+Plugin' in my pom.xml Also added the configuraiton under 'reporting' tag for cobertura-maven-plugin But while executing the build from hudson - I am getting the following exception Skipping Cobertura coverage report as build was not UNSTABLE or better ... Finished: FAILURE I have configured the plugin "Publish Cobertura Coverage Report" in Hudson Am I missing any steps during configuration?Maxantia
check your logs, it should show some failure messages. also running mvn site cobertura:cobertura on a local checkout might help. Also as a note, for me, just running "cobertura:cobertura" as a goal was enough, no pom changes were necessary (possibly because an upper level pom already included it...)Rego
C
25

Hudson needs a you to generate the coverage.xml file. To do this without changing your pom.xml, you can use:

mvn cobertura:cobertura -Dcobertura.report.format=xml
Counterstamp answered 20/9, 2013 at 16:13 Comment(6)
On my system the <configuration> section of the plugin is not respected.. However, it works when I specify the above -Dcobertura.report.format parameter in the line of goals. Thx amcknightZachar
Is there any way to generate Cobertura reports on mvn clean install command instead of mvn cobertura:cobertura, When I changed the executions- phase as test and goal as cobertura, it works but it is running test cases twice, any idea on this?Chevron
@PRATHAPS, I know it is a very late comment, but did you figure out how to fix this? Both your solution and Johan Norén's answers runs the test cases twice. Did you figure out to run the test cases only once and generate the cobertura report from that single test run?Record
@Record what I figured out was it will run twice always. But it doesn't matter as it is not affecting any performance since tests will run only before build. Later started using JacacoChevron
@PRATHAPS, thanks a lot for your reply! My only concern was, we run the full build before merging the code in to the repo. Developers will (should) do it before merging. If the tests run twice, it will cause waste developers' time. The plan was not just to create the coverage report in build systems, but to check and fail the build if the sufficient coverage is not present. So, I can understand from your reply and my experience that it will always run twice if we want to check. BTW, jacoco doesn't run twice? Can it achieve reporting and checking during a single test run? Thanks in advance!Record
@Record Yes, Jacoco doesn't run tests twice. We can achieve reporting and all other features what Cobertura haveChevron
C
8

To run Cobertura during package phase, do

            <plugin>  
                <groupId>org.codehaus.mojo</groupId>  
                <artifactId>cobertura-maven-plugin</artifactId>  
                <version>2.5.2</version>  
                <configuration>  
                    <formats>  
                        <format>xml</format>  
                    </formats>  
                </configuration>  
                <executions>  
                    <execution>  
                        <phase>package</phase>  
                        <goals>  
                            <goal>cobertura</goal>  
                        </goals>  
                    </execution>  
                </executions>  
            </plugin>         

Heres an example of pom

http://macgyverdev.blogspot.com/2011/04/development-environment-for-google-app.html

And here how to integrate in Hudson http://macgyverdev.blogspot.com/2011/04/hudson-continous-integration-for-google.html

Crocidolite answered 22/4, 2011 at 7:31 Comment(1)
With this configuration, the test cases are run twice. Any idea how to fix it so that the tests are run only once, and the cobertura report is generated using that?Record
O
1

Cobertura doesn't actually seem to work with hudson.

I have a project where executing the command line: mvn clean package

Builds a coverage report generates an accurate coverage report with an average coverage of about 78% line and 74% branch.

Running the same goals on a Hudson server results in a coverage report showing 0% 0%.

Unfortunately the Jira site for the plugin doesn't seem to allow anyone to post issues so this issue is as yet unreported to the team.

Okay answered 30/1, 2012 at 22:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.