![]() | ![]() |
Apache > Jakarta > Cactus > Running Tests > Ant | Docs for: v1.7.1 | v1.7 Last update: September 2 2005 |
Ant IntegrationCactus provides strong integration with the popular build tool Ant. This integration consists of a handful of tasks that support the running of tests from an Ant build file. BackgroundA strong principle of eXtreme Programming (XP) is the continuous integration aspect (see the Continuous Integration article by Martin Fowler). The traditional approach to the development of complex software has been to separate the development process into phases of coding, testing and integration. The continuous integration principle is to basically code, test and integrate at the same time, so that at almost any point in time, you have a working product. In order to achieve this, you need to be able to automatically build your entire application, including running the unit and acceptance tests. Thus, tools such as Ant or Maven are the foundation for continuous integration. You can build on that foundation by using a dedicated continuous integration tool like CruiseControl, Gump or AntHill. Ant is written in Java and provides a wide variety of tasks that support the development of Java applications (though it is in no way restricted to development). In addition, many third-party tasks are available, and it is quite easy to extend Ant with custom tasks. Ant ResourcesThis documentation assumes good knowledge of the basic concepts of Ant. Here are several resources that can help you get up to speed if you haven't been using Ant yet:
A full list of resources is maintained by the Ant team at http://ant.apache.org/resources.html Installing the Cactus Ant Tasks
The Ant tasks provided by Cactus are distributed together with the
main distribution of Cactus, which you can get from the
download area. After downloading
and expanding the archive, you'll find several JAR files in the
It is recommended that you copy these JARs into the project for which
you are writing Cactus tests. A common pattern is to have a
[your project] |- doc | ... |- lib | |- cactus.jar | |- cactus-ant.jar | |- commons-httpclient.jar | |- commons-logging.jar | |- junit.jar | |- aspectjrt.jar |- src | |- java | | ... | |- test | | ... |- build.xml
Of course, you can put them anywhere you want as long as you
can correctly locate them from within your build file. Another
option is to put all the libraries in the
There's one step left to enable your project to run Cactus tests
from within Ant: you'll need to introduce the Cactus tasks to Ant.
This is done with a <!-- Define the Cactus tasks --> <taskdef resource="cactus.tasks"> <classpath> <pathelement location="lib/cactus.jar"/> <pathelement location="lib/cactus-ant.jar"/> <pathelement location="lib/commons-httpclient.jar"/> <pathelement location="lib/commons-logging.jar"/> <pathelement location="lib/aspectjrt.jar"/> </classpath> </taskdef>
As you can see, you'll need to add the JARs required by Cactus to the
If you get an error at this point, make absolutely sure that you've
correctly set up the classpath for the task definition. Run Ant with
the
-verbose or the -debug options to find
out which libraries or classes could not be found, or what else may
be going wrong.
Using the Cactus Ant TasksAfter you have defined the Cactus tasks you'll need to actually use them in the build file to run the Cactus tests. Cactus provides a couple of tasks that support you with running the tests from an Ant build. Each of the tasks is independant or complementary to the others. You'll need to decide on what tasks to used depending on your requirements.
Typically, the sequence for executing Cactus tests from an Ant build will be the following:
|