Appendix D. Running tests with Ant

 

Apache Ant is the de facto build tool used by Java developers all around the world. Not surprisingly, Ant has had JUnit integration as long as I can remember. Here’s a quick tutorial for creating an Ant script that runs our unit tests and cranks out a pretty HTML report of the results. If you’re not familiar with Ant, please refer to the online documentation[1] or grab one of the excellent books on the topic.[2]

1 Especially the User’s Manual (http://ant.apache.org/manual) and the Ant Wiki (http://wiki.apache.org/ant).

2 I would personally recommend Ant in Action by Steve Loughran and Erik Hatcher (Manning Publications, 2007). It’s basically a 2nd edition of their earlier book, Java Development with Ant (Manning Publications, 2002).

Let’s start our little tutorial and see what kind of a project we’re dealing with.

Apache Ant and JUnit 4 compatibility

JUnit 4 support was introduced in the 1.7 release of Apache Ant, which means that you’ll need to downgrade your tests to use JUnit 3.8 if you don’t have or cannot upgrade your Ant version to the 1.7 branch. The versions of Ant and JUnit you’re using do not, however, affect your build script.

D.1. Project directory structure

 
 

D.2. The basics: compiling all source code

 
 

D.3. Adding a target for running tests

 
 

D.4. Generating a human-readable report

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest