How do I generate a unit test report for a site?
Author: Deron Eriksson
Description: This maven tutorial describes how to generate a unit test report for a site using the Maven Surefire Report Plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page:    1 2 >

The MavenSW Surefire Report Plugin can be used to automatically generate a report of the results of your project's unit tests. To include the unit test report in the project documentation site, add the maven-surefire-report-plugin to the reporting section of your project's pom.xml. In addition, if you'd like to be able to automatically link from your failed unit tests to the source code of the unit test, you can do this by including the maven-jxr-plugin in the reporting section too, which generates a JXR xref representation of your source code and test source code.

reporting section of pom.xml

	<reporting>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-report-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jxr-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.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-report-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jxr-plugin</artifactId>
			</plugin>
		</plugins>
	</reporting>
</project>

To build the site documentation but not deploy it, we can do:

mvn clean site

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 linked to here.

Console output for 'mvn clean site-deploy'

(Continued on page 2)

Page:    1 2 >


Related Tutorials: