Lab: Building with Ant

Steven J Zeil

Last modified: Mar 20, 2014

Contents:
1. Find That Project
2. Compiling and Cleaning Up
3. Running Unit Tests

This is a self-assessment activity to give you practice in working with the ant build manager. Feel free to share your problems, experiences, and choices in the Forum.

1. Find That Project

In a previous lab, you set up an Eclipse project with a Java program and some unit tests.

We’ll use that as a starting point for this lab.

2. Compiling and Cleaning Up

In your project directory, create a build.xml file. You can do this with the Eclipse editor if you like. Eclipse has an ant-specific editor, basically a slightly dressed-up version of its regular text editor. There’s also a special XML editor which knows less about ant build files but offers more help with the general XML syntax.

You can also use any other text editor outside of Eclipse, but remember to refresh your Eclipse project after adding any new fles to the project directory by non-Eclipse means.

3. Running Unit Tests

If you only have a single JUnit test in your project , try splitting it or duplicating it to form two separate tests.

Add a new target ‘test’ to your build.xml file, dependent on the earlier build target. The ‘test’ target should run your JUnit tests (Ant task junit). Run ant test (from Eclipse or from the command line), observing both the immediate output and the test results recorded. (Eclipse may be unaware that JUnit has deposited report files in your project until you refresh the directory.)

Try experimenting with the four different formatters and see how their output looks.

After you have looked at the formatters, select the XML formatter and add to your test target a use of the junitreport task. You should be able to produce an HTML summary report of all of your tests.