TestNG Maven plug-ins

Table of Contents

Maven 2

Maven2 should support TestNG out of the box without the need to download any additional plugins (other than TestNG itself).

Snapshot Build Updates

The latest current good version of the Surefire plugin that you want is 2.4. You can find the full instructions on the Surefire web site (here are the TestNG-specific instructions).

Configuration

Goals
GoalDescription
testCompiles and runs your tests
siteCreates your Maven generated site, which will include the TestNG report output.

Properties

PropertyOptional?Description
includesNoComma delimited list of regexp patterns to include source files with. Ie **/Test*.java
groupsYesComma delimited list of groups to be included in test. If left blank will run all tests by default.
excludeGroupsYesComma delimited list of groups that should not be included in test run.
suiteXmlFilesYesComma delimited list of file paths pointing to testng.xml suite files. (src/test-data/testng-core.xml,src/test-data/testng-functional.xml)

Warning: When defining suiteXmlFiles most of the other parameters are ignored.

threadCountYesNumber of threads to run for tests
parallelYesWhen using threads, whether or not to run them in parallel. Use tests to have each test run in its own thread or methods to have the methods invoked from different threads.

Java 1.4

In order to use javadoc style annotations you currently must run Maven with a java 1.4 jvm in order for them to be seen. If you try running your javadoc annotated tests in a 1.5 jvm they will most likely not be found. It is hoped in a future release this problem will be eliminated.

Sample Report

A sample surefire report with TestNG can be found here.


Maven TestNG Archetype (Martin Gilday)

Martin Gilday has added a new archetype for Maven2 users that should make it easier to get going with TestNG. You can find more about this in his blog entry here, but the basics for configuring it have been pasted below.

To create a project using the archetype you simply have to specify my repository and the archetype ID.

  mvn archetype:create -DgroupId=org.martingilday -DartifactId=test1 -DarchetypeGroupId=org.martingilday -DarchetypeArtifactId=testng-archetype
    -DarchetypeVersion=1.0-SNAPSHOT -DremoteRepositories=http://www.martingilday.org/repository/

Of course substitute in your own groupId and artifactId.

Don't forget to keep checking back at Martin's blog for more updates.



Maven 1 (by Andrew Glover)

The TestNG Maven plug-in is quite simple and consists of two goals and a series of optional properties.

Currently the 1.1 version of the plug-in is bundled with official releases of TestNG. To utilize the plug-in, copy the maven-testng-plugin-.jar to the $MAVEN_HOME/plugins directory.

For the latest version of the plug-in (1.2 as of 12/12/05), update your maven.repo.remote to include http://www.vanwardtechnologies.com/repository/ and then issue the following command: maven plugin:download. Maven will issue a series of questions, answer them as follows:

artifactId: maven-testng-plugin
groupId: testng
version: 1.2

Goals

Goal Description
testng Runs TestNG
testng:junit-report Creates a JUnit style report

Properties

Property Optional? Description
maven.testng.suitexml.name Yes XML file name- defaults to testng.xml
maven.testng.suitexml.dir Yes Directory where XML file lives. Defaults to ${basedir}/test/conf
maven.testng.output.dir Yes Default report directory. Defaults to ${maven.build.dir}/testng-output
maven.testng.source.dir Yes For 1.4- where test source is. Defaults to ${basedir}/test/java/
maven.testng.report.dir Yes Directory for JUnit reports. Defaults to ${maven.build.dir}/testngJunitReport

A sample JUnit sytle report generated via the TestNG maven plug-in can be found here.