17.3. Ant integration

17.3.1. Obtaining the Ant Plugin
17.3.2. Installing the Ant Plugin
17.3.3. Using the Ant Plugin
17.3.4. Ant Plugin XML reference

Apache Ant is a software tool for automating software build processes. It is similar to make but it is written in Java and requires a Java runtime to execute it. Ant is cross-platform to the extent that Java is, and is best suited to building Java projects.

The Squish plugin for Ant makes it possible to run Squish tests from an Ant build file.

17.3.1. Obtaining the Ant Plugin

The Ant plugin is available from: www.froglogic.com/download/squish-ant-plugin_latest.jar.

17.3.2. Installing the Ant Plugin

The Ant plugin can be installed in any of the ways listed below:

  • Copy the jar file to ANT_HOME/lib. This often requires Administrator rights.

  • Copy the jar file to USER_HOME/.ant/lib.

  • When calling ant use the -lib option to specify the Squish plugin.

Details for installing external Ant libraries are described in the Ant Installation Manual.

17.3.3. Using the Ant Plugin

Here is a typical Ant build.xml file:


<project name="MyProject" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

To use the plugin functionality, the Squish object (Squish Object (Section 16.1.9.22)) must be mentioned. For example:

<project name="MyProject" basedir="." xmlns:squish="antlib:com.froglogic.squish.ant">
    <description>
        simple example build file
    </description>
    ...

In this case it may make sense to run the Squish test as a separate target. The following will accomplish this:

    ...
  <target name="test" depends="compile"
    description="run the tests">
    <squish:runtest suite="C:\squish\examples\qt3\suite_addressbook_js" path="C:\squish" />
  </target>
    ...

Running a Squish test from the command line produces the following output for the above example when using target test:

$ ant test
Buildfile: build.xml

init:

test:
[squish:runtest] Running testcase: add_address_datadriven took 47.0s
[squish:runtest] Running testcase: add_address took 16.0s
[squish:runtest] Tests run : 2, Failures : 0, Errors : 0, Fatals : 0

BUILD SUCCESSFUL
Total time: 1 minute 3 seconds

17.3.4. Ant Plugin XML reference

This section provides an overview of the tags that can be used after installing the Ant plugin.

17.3.4.1. squish:config

The squish:config tag can be used as a convenient way to set the path to the Squish installation that should be used to run the tests. The table below shows the attributes that can be used:

Table 17.1. Config tag

Attribute Value
path The absolute path to Squish's root directory.
host The hostname where the squishserver is running.
port The port number that the squishserver is listening on.
snoozeFactor The snooze factor to use when running Squish tests.
reportDir The directory where test reports should be output to.


Here is an example of using the squish:config tag in an Ant build file:

<project name="MyProject" basedir="." xmlns:squish="antlib:com.froglogic.squish.ant">

    <squish:config path="C:\squish"/>

    <target>
    ...

When the squish:config tag is used at the start of the document—as in the above example—the path that is set is used for all the Squish tests in the targets. For finer control, the squish:config tag can be used inside a target container, in which case the path will only apply to tests in that container.

[Note]Note

It is also possible to set the Squish path in the squish:runtest tag, but if there are many Squish tests to be run and they all use the same Squish installation, using the squish:config tag is much more convenient.

17.3.4.2. squish:runtest

The squish:runtest tag can be used to run a Squish test case or test suite. The table below shows the attributes that can be used:

Table 17.2. squish:runtest tag

Attribute Value Required
suite The absolute path to the Squish suite that is to be run. Yes
testcase The one test case from the suite to be run. (If this is not specified then all of the suite's test cases will be run.) No
host The hostname of the machine where the squishserver is running. No
port The port number that the squishserver is listening on. No
snoozeFactor The snooze factor to use when running the test case or cases. No
path The absolute path to Squish's root directory. No
haltonerror Whether to stop the build when a test error occurs—the default is false. No


[Note]Note

The attributes host and port are not marked as required since they can alternatively be set using the squish:config tag.

Here is an example of using the squish:runtest tag in an Ant build file:

<project name="MyProject" basedir="." xmlns:squish="antlib:com.froglogic.squish.ant">
    ...
  <target name="test" depends="compile"
    <description> run the tests </description>
    <squish:runtest suite="C:\squish\examples\qt3\suite_addressbook_js"
     testcase="add_address" path="C:\squish" />
  </target>
    ...

For the squish:runtest tag to work, the suite attribute must indicate a valid Squish suite. Also, the absolute path to the Squish installation to use for running tests must be known, either by using the squish:runtest tag's path attribute or the squish:config tag's path attribute. When an ant process runs a Squish test, it waits for the test to be completed; the results are reported back on the standard output (e.g., the console).