James Mead in Hellish XML:
So now you can write test cases for ANT in XML using AntUnit. You can even write assertions in XML ...<!-- the actual test case --> <target name="testTouchCreatesFile"> <au:assertFileDoesntExist file="${foo}"/> <touch file="${foo}"/> <au:assertFileExists file="${foo}"/> </target>... but why?
The short answer is: Because it is the best way to test Ant tasks.
To answer this in more detail I need to put AntUnit into context a little bit.
Despite its name AntUnit is more about functional and integration testing than unit testing. Nobody suggests you should write unit tests for your Java (or Ruby) project in Ant instead of the testing framework that fits your language or problem domain. In fact Ant will certainly stick with JUnit 3.x for "real" unit tests of its internals.
AntUnit's main purpose was and is testing Ant tasks. As such it is quite natural to express the tests using a language familiar to Ant developers and users - as Ant build files.
Ant's own tests started out as a collection of ad-hoc JUnit tests
in the early days of JUnit 3.x and Ant 1.1 sometime during the summer
of 2000. Pretty soon an Ant domain specific JUnit extension was born,
BuildFileTest
which contains some logic for setting up Ant Project
instances from test build files and a few Ant specific assertion
methods.
Over time many tests degraded to stuff like
public void testSomeSpecificProperty() { executeTarget("someSpecificProperty"); }
and the actual assertions were performed using <fail> tasks inside of the build file. JUnit wasn't used as a Java testing framework but as a driver for Ant.
We could do better than that, AntUnit was born. Ad-hoc <macrodef>s using <fail> are now replaced by a standard set of assertion tasks and a new task acts as a driver for tests - no reason to abuse JUnit any longer.
There also is an important side effect of using AntUnit as Ant's testing framework: it has become absolutely straight forward to turn a bug report into a test. If a user reports a bug all we need now is a sample build file snippet that exhibits the bug. Glue an assertion at the end and you are done.
path: /en/Apache/Ant/AntUnit | #