Functional Testing with Cargo, HtmlUnit, and Maven 2
This article will show you how to set up a web application with Maven 2, and perform an automated functional test using Cargo, HtmlUnit and Maven 2.
# Set up a multi-module Maven Project ===
For this example, we will need a module for the web application, and one for the functional tests. First, lets create a directory called "myproject" to contain the modules. In the following examples, the "~" symbol represents your home directory, but you can create this directory anywhere you want.
From the 'myproject' directory, use the Maven Archetype plugin to create two modules. In the following example, the "it" in "myproject-it" stands for "integration tests". This represents the phase of Maven's build lifecycle in which these tests will run. The artifactIds and resulting directory names are arbitrary, so feel free to use whatever you want in your own projects.
Save the following as pom.xml in the 'myproject' directory:
Add the HtmlUnit and Cargo dependencies to myproject-it/pom.xml. The exclusion for jsr173 will save you from having to go find and install it, since it is one of the Sun jars that can't be placed in a public Maven repository due to licencing, and it isn't necessary for this example.
If you use an IDE such as IntelliJ? IDEA, chances are that Maven can create the configuration files for you. For example:
# Developer Setup ==
You must configure the location of Tomcat 5x before you run the tests. You can either do this on the command line with -Dcargo.tomcat5x.home=c:/java/apache-tomcat-5.5.15, or you can configure a property in settings.xml and later reference it in myproject-it/pom.xml.
Here is settings.xml, which is usually stored in the "~/.m2" directory. Remember that "~" refers to your "home directory". On Windows, that's usually c:\Documents and Settings\yourid.
* Cargo http://cargo.codehaus.org
* HtmlUnit http://htmlunit.sourceforge.net/
* Maven http://maven.apache.org