Last modified: Mar 20, 2014
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.
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.
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.
Try creating a build file that will do two things at first:
You may want to keep the Apache Ant Manual open to the “Ant Tasks” section while you are woking on this.
Run your build script from inside Eclipse by right-clicking on the build.xml file and selecting "Run as > ant build. Assuming that works, check to see that hte appropriate.class` files have been produced.
Now right-click on the build.xml file and selecting "Run as > ant build…. The "..." form will offer up a list of targets for you to choose from. Choose your clean` target.
Open up a command window, cd to the directory holding your project, and try running ant from there. (You may need to install ant first, if it is not already on your system.)
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.