ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Unit test a build
Date Tue, 24 Jan 2006 04:58:50 GMT
On Mon, 23 Jan 2006, Ninju Bohra <> wrote:

> I too created test cases for my build files (actually they are build
> files for testing my custom tasks, but they are still build files).
> I used the BuildFileTest class as the base class (that my JUnit
> classes extended from).

This is the traditional way Ant used itself, but this is going to be
replaced by AntUnit step by step.  The difference is that you don't
write a Java class at all.

Say I want to test the <touch> task and validate it creates a file, I
write a build file:

<project xmlns:au="antlib:org.apache.ant.antunit">
  <property name="foo" value="foo"/>

  <target name="tearDown">
    <delete file="${foo}" quiet="true"/>

  <target name="testTouchCreatesFile">
    <au:assertFileDoesntExist name="${foo}"/>
    <touch file="${foo}"/>
    <au:assertFileExists name="${foo}"/>

> The class provided some convience methods for reading the build.xml,
> initializing the project, and accessing property and log output
> (very useful when verified build behavior).

AntUnit provides a generic <assert> task (with a nested condition) as
well as a bunch of macrodef'ed asserts and

> but I never quite thought of "testing" a build script with unit
> tests (it seems a bit recursive as you would need a build script to
> invoke the build you are testing...)

an <antunit> task to do just that.  The task takes a bunch of build
files and runs the targets whose names start with "test", with special
handling for targets names setUp and tearDown.  And it provides for
test listeners.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message