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'

[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] ************************************************************** 
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
[INFO] Velocimacro : error using  VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm'
[INFO] Velocimacro :  VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates
[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be  global in scope if allowed.
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[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 surefire-report:report
[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] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 1 source file 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
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.046 sec <<< FAILURE!

Results :

Failed tests: 
  testApp(com.maventest.AppTest)

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[ERROR] There are test failures.

Please refer to C:\dev\workspace\aproject\target\surefire-reports for the individual test results.
[INFO] Preparing surefire-report:report-only
[INFO] No goals needed for project - skipping
[INFO] [site:site]
[INFO] Skipped "Maven Surefire Report" report, file "surefire-report.html" already exists for the English version.
[INFO] Generating "Maven Surefire Report" report.
[INFO] Generating "Source Xref" report.
[WARNING] Unable to locate Javadoc to link to - DISABLED
[INFO] Generating "Test Source Xref" report.
[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  
Uploading: ./css/maven-base.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2371 bytes copied in 0.011 seconds
Uploading: ./css/maven-theme.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2801 bytes copied in 0.0080 seconds
Uploading: ./css/print.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 222 bytes copied in 0.0080 seconds
Uploading: ./css/site.css to http://192.168.1.7/sites/aproject/


Transfer finished. 0 bytes copied in 0.0070 seconds
Uploading: ./dependencies.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 5420 bytes copied in 0.012 seconds
Uploading: ./images/collapsed.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 53 bytes copied in 0.0080 seconds
Uploading: ./images/expanded.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 52 bytes copied in 0.0080 seconds
Uploading: ./images/external.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 230 bytes copied in 0.217 seconds
Uploading: ./images/icon_error_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1010 bytes copied in 0.0070 seconds
Uploading: ./images/icon_info_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 606 bytes copied in 0.0080 seconds
Uploading: ./images/icon_success_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 990 bytes copied in 0.0090 seconds
Uploading: ./images/icon_warning_sml.gif to http://192.168.1.7/sites/aproject/

#
Transfer finished. 576 bytes copied in 0.0070 seconds
Uploading: ./images/logos/build-by-maven-black.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2294 bytes copied in 0.011 seconds
Uploading: ./images/logos/build-by-maven-white.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2260 bytes copied in 0.0090 seconds
Uploading: ./images/logos/maven-feather.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3330 bytes copied in 0.0090 seconds
Uploading: ./images/newwindow.png to http://192.168.1.7/sites/aproject/

#
Transfer finished. 220 bytes copied in 0.0080 seconds
Uploading: ./index.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3978 bytes copied in 0.01 seconds
Uploading: ./integration.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 4024 bytes copied in 0.011 seconds
Uploading: ./issue-tracking.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3988 bytes copied in 0.0090 seconds
Uploading: ./license.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3971 bytes copied in 0.017 seconds
Uploading: ./mail-lists.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3999 bytes copied in 0.01 seconds
Uploading: ./project-info.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 6016 bytes copied in 0.018 seconds
Uploading: ./project-reports.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3952 bytes copied in 0.01 seconds
Uploading: ./project-summary.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 4797 bytes copied in 0.013 seconds
Uploading: ./source-repository.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 4006 bytes copied in 0.01 seconds
Uploading: ./surefire-report.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 7804 bytes copied in 0.011 seconds
Uploading: ./team-list.html to http://192.168.1.7/sites/aproject/

##
Transfer finished. 5139 bytes copied in 0.012 seconds
Uploading: ./xref/allclasses-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 610 bytes copied in 0.0070 seconds
Uploading: ./xref/com/maventest/App.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1555 bytes copied in 0.012 seconds
Uploading: ./xref/com/maventest/Howdy.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1913 bytes copied in 0.011 seconds
Uploading: ./xref/com/maventest/package-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 798 bytes copied in 0.0090 seconds
Uploading: ./xref/com/maventest/package-summary.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 2086 bytes copied in 0.0090 seconds
Uploading: ./xref/index.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 807 bytes copied in 0.01 seconds
Uploading: ./xref/overview-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 637 bytes copied in 0.01 seconds
Uploading: ./xref/overview-summary.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1613 bytes copied in 0.0080 seconds
Uploading: ./xref/stylesheet.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1687 bytes copied in 0.011 seconds
Uploading: ./xref-test/allclasses-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 526 bytes copied in 0.011 seconds
Uploading: ./xref-test/com/maventest/AppTest.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 3599 bytes copied in 0.0090 seconds
Uploading: ./xref-test/com/maventest/package-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 695 bytes copied in 0.0090 seconds
Uploading: ./xref-test/com/maventest/package-summary.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1936 bytes copied in 0.0080 seconds
Uploading: ./xref-test/index.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 807 bytes copied in 0.0080 seconds
Uploading: ./xref-test/overview-frame.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 637 bytes copied in 0.0070 seconds
Uploading: ./xref-test/overview-summary.html to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1613 bytes copied in 0.0080 seconds
Uploading: ./xref-test/stylesheet.css to http://192.168.1.7/sites/aproject/

#
Transfer finished. 1687 bytes copied in 0.012 seconds
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: 11 seconds
[INFO] Finished at: Fri Feb 22 17:37:14 PST 2008
[INFO] Final Memory: 27M/49M
[INFO] ------------------------------------------------------------------------

(Continued on page 2)

Page:    1 2 >


Related Tutorials: