How do I generate a Cobertura test coverage report for a site?
Author: Deron Eriksson
Description: This maven tutorial describes how to generate a test coverage report for a site using the Cobertura Maven Plugin.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
The Cobertura MavenSW Plugin is a cool plugin that analyzes how well your unit tests cover the code in your project source code. It can generate a code coverage report for your project documentation site if you add a cobertura-maven-plugin entry to the reporting section of your pom.xml. section of pom.xml<reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </reporting> My project's complete pom.xml file is shown here. It includes some code to deploy to my ApacheSW server using webdav. pom.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.maventest</groupId> <artifactId>aproject</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>aproject</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <extensions> <!-- start - for deploying using webdav --> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-webdav</artifactId> <version>1.0-beta-2</version> </extension> <!-- end - for deploying using webdav --> </extensions> </build> <distributionManagement> <!-- start - location where site is deployed - username/password for site.deployments in server.xml --> <site> <id>site.deployments</id> <name>Site deployments</name> <url>dav:http://192.168.1.7/sites/${artifactId}/</url> </site> <!-- end - location where site is deployed - username/password for site.deployments in server.xml --> </distributionManagement> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </reporting> </project> To build the site documentation but not deploy it, we can do: mvn clean site However, I'd like to build and deploy the site, so I'll do the following: mvn clean site-deploy The console output from 'mvn clean site-deploy' is shown here. Console output for 'mvn clean site-deploy'[INFO] Scanning for projects... WAGON_VERSION: 1.0-beta-2 [INFO] ------------------------------------------------------------------------ [INFO] Building aproject [INFO] task-segment: [clean, site-deploy] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean] [INFO] Deleting directory C:\dev\workspace\aproject\target [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] Preparing cobertura:cobertura [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 2 source files to C:\dev\workspace\aproject\target\classes [INFO] [cobertura:instrument] [INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Instrumenting 2 files to C:\dev\workspace\aproject\target\generated-classes\cobertura Cobertura: Saved information on 2 classes. Instrument time: 114ms [INFO] Instrumentation was successful. [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 2 source files to C:\dev\workspace\aproject\target\test-classes [INFO] [surefire:test] [INFO] Surefire report directory: C:\dev\workspace\aproject\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.maventest.AppTest Hello World! Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.055 sec Running com.maventest.HowdyTest Howdy says hello! Howdy says hello! Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec Results : Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 Cobertura: Loaded information on 2 classes. Cobertura: Saved information on 2 classes. [INFO] [site:site] [INFO] Generating "Cobertura Test Coverage" report. [INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 2 classes. Report time: 225ms [INFO] Cobertura Report generation was successful. [INFO] Generating "Continuous Integration" report. [INFO] Generating "Dependencies" report. [INFO] Generating "Issue Tracking" report. [INFO] Generating "Project License" report. [INFO] Generating "Mailing Lists" report. [INFO] Generating "About" report. [INFO] Generating "Project Summary" report. [INFO] Generating "Source Repository" report. [INFO] Generating "Project Team" report. [INFO] [site:deploy] http://192.168.1.7/sites/aproject/ - Session: Opened ... REMOVED FOR CLARITY ... http://192.168.1.7/sites/aproject/ - Session: Disconnecting http://192.168.1.7/sites/aproject/ - Session: Disconnected [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 13 seconds [INFO] Finished at: Sat Feb 23 06:21:43 PST 2008 [INFO] Final Memory: 21M/41M [INFO] ------------------------------------------------------------------------ (Continued on page 2) Related Tutorials:
|