CargoHtmlUnitMaven

HomePage | RecentChanges | Preferences

Difference (from prior major revision) (no other diffs)

Changed: 1,107c1

Functional Testing with Cargo, HtmlUnit, and Maven 2




<toc>

1. Introduction




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.

2. Project Setup ==


# 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.


~
$ mkdir myproject
$ cd myproject


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.


~/myproject
$ mvn archetype:create -DgroupId=com.example -DartifactId=myproject-webapp -DarchetypeArtifactId=maven-archetype-webapp
$ mvn archetype:create -DgroupId=com.example -DartifactId=myproject-it

2.1. Add the parent POM




Save the following as pom.xml in the 'myproject' directory:

... TODO ...

2.2. Add additional dependencies




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.

<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>javax.xml</groupId>
<artifactId>jsr173</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-uberjar</artifactId>
<version>0.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-ant</artifactId>
<version>0.8</version>
<scope>test</scope>
</dependency>

2.3. Configure your IDE




If you use an IDE such as IntelliJ? IDEA, chances are that Maven can create the configuration files for you. For example:

~/myproject
$ mvn idea:idea

3. Test Execution ==


# 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.


<settings>
...
<profiles>
...
<profile>
<id>cargo-config</id>
<properties>
<cargo.tomcat5x.home>c:/java/apache-tomcat-5.5.15</cargo.tomcat5x.home>
</properties>
</profile>
</profiles>

<activeProfiles>
<activeProfile>cargo-config</activeProfile>
</activeProfiles>

</settings>

4. References



* Cargo http://cargo.codehaus.org
* HtmlUnit http://htmlunit.sourceforge.net/
* Maven http://maven.apache.org



HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited December 21, 2019 1:07 pm by 78-93-98-198.dsl.wavetel.us (diff)
Search: