concept AntUnit in category ant

This is an excerpt from Manning's book Ant in Action.
AntUnit is an Antlib, a library of extra tasks with the filename ant-antunit.jar. It contains the Java tasks and macros to turn build files into test suites. The <antunit> task will load a build file and run every target in it whose name matches the pattern test?*, executing the optional setUp and tearDown targets before and after each test target. The Antlib includes a set of assertion tasks to check the state of the project in the test.
AntUnit is Ant’s equivalent of JUnit. It has its own home page, http://ant.apache.org/antlibs/antunit. This web site contains AntUnit documentation and the JAR, ant-antunit.jar. The JAR can be added to ANT_HOME/lib or ${user-home}/.ant/lib, or it can be dynamically loaded via a taskdef declaration. We keep it in ANT_HOME/lib, because we use it so often.
We know enough about AntUnit to use it. It’s time to add tests to the build by running the <antunit> against our own build file:
<target name="antunit" depends="ready-to-run" xmlns:au="antlib:org.apache.ant.antunit"> <au:antunit> <fileset file="${ant.file}"/> <au:plainlistener/> </au:antunit> </target>Calling this target will trigger a run against the test targets in the file and the optional setUp and tearDown targets. The antunit target is set to depend upon the ready-to-run target, which ensures that the source is compiled before the tests run. The individual test targets do not depend upon this. If they did, every test target would also have the complete compile step re-executed, because when AntUnit runs a target, it runs all its dependencies. Instead, the test targets depend on the define target, which declares the custom task with <taskdef>.
To use AntUnit in a build file, you need to declare the Antlib namespace in the project or in targets that use the new tasks: