O'Reilly logo

Jenkins: The Definitive Guide by John Ferguson Smart

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Automating Your Tests with Ant

Setting up automated testing in Ant is also relatively easy, though it requires a bit more plumbing than with Maven. In particular, Ant does not come packaged with the JUnit libraries or Ant tasks out of the box, so you have to install them somewhere yourself. The most portable approach is to use a Dependency Management tool such as Ivy, or to place the corresponding JAR files in a directory within your project structure.

To run your tests in Ant, you call the <junit> task. A typical Jenkins-friendly configuration is shown in this example:

<property name="build.dir" value="target" />
<property name="java.classes" value="${build.dir}/classes" />
<property name="test.classes" value="${build.dir}/test-classes" />
<property name="test.reports" value="${build.dir}/test-reports" />
<property name="lib" value="${build.dir}/lib" />

<path id="test.classpath">1
  <pathelement location="${basedir}/tools/junit/*.jar" />
  <pathelement location="${java.classes}" />
  <pathelement location="${lib}" />
</path>

<target name="test" depends="test-compile">
  <junit haltonfailure="no" failureproperty="failed">2
    <classpath>3 <path refid="test.classpath" /> <pathelement location="${test.classes}" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required