Cobertura and Jetty

I am trying to get a coverage report when I launch my webapp on Jetty using cobertura. We already have cobertura for unit tests using the surefire plugin. We also have a secure plugin configured to run our integration tests.

I already (manually) measured my war and launched it.

When running mvn verify with integration tests only the profile, it seems Cobertura works because I get all kinds of new warnings in the Eclipse console (I run the jetty from there), probably because the bytecode is changed by Cobertura. But I can not write the .ser file even when I call "stop" on the mooring server.

I get a .ser file when mvn cobertura:cobertura and the report is generated at the target/site directory of my web application. The report shows a 0% coverage because cobertura:cobertura does not perform any tests.

How to run integration tests using failover make cobertura? Any other suggestions?

Thanks Ben

+4
source share
2 answers

I solved this problem using the cobertura-it plugin. It extends the original cobertura plugin and allows you to use the target only for reporting. In addition, I have to run two separate commands (see below) to test and create reports (merging with 1 command does not work). Here is my plugin configuration.

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-it-maven-plugin</artifactId> <version>2.5</version> <configuration> <formats> <format>html</format> </formats> <check> <haltOnFailure>false</haltOnFailure> </check> </configuration> <executions> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>7.4.2.v20110526</version> <configuration> <stopKey>aaaaaaaaaaaaa</stopKey> <stopPort>8085</stopPort> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> <classesDirectory>target/generated-classes/cobertura</classesDirectory> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>net.sourceforge.cobertura</groupId> <artifactId>cobertura</artifactId> <version>1.9.4.1</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>integration-test</id> <phase>integration-test</phase> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <phase>verify</phase> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin> 

So I run this: mvn clean verify

Note that there are several cobertura messages after stopping Jetty:

 [INFO] ------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------- [INFO] Total time: 1 minute 13 seconds [INFO] Finished at: Sun Nov 13 12:58:29 ICT 2011 [INFO] Final Memory: 86M/204M [INFO] ------------------------------------------------------- 2011-11-13 12:58:29.765:WARN::4 threads could not be stopped Flushing results... Flushing results done Cobertura: Loaded information on 342 classes. Cobertura: Saved information on 342 classes. 

Finally, I use mvn site to create reports. Here is the configuration of my report

 <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <!-- An error on version 2.8 --> <version>2.7</version> <configuration> <reportsDirectories> <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> <reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory> </reportsDirectories> </configuration> <reportSets> <reportSet> <reports> <report>report-only</report> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.1</version> <configuration> <!-- An error that takes long time to generate this report --> <dependencyLocationsEnabled>false</dependencyLocationsEnabled> </configuration> <reportSets> <reportSet> <reports> <report>dependencies</report> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-it-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> 
+5
source

Perhaps you need the <execution> for your cobertura-maven-plugin configuration. There are some examples at http://mojo.codehaus.org/cobertura-maven-plugin/instrumentingDeploymentArtifact.html , but this answer looks better: What is the correct way to use Cobertura with Maven 3.0.2

0
source

Source: https://habr.com/ru/post/901229/


All Articles