To begin, download coverage.zip and unzip its contents to a new directory. Since Java build environments tend to require complex configuration, the .ZIP file contains a pre-configured Apache Ant build environment for JUnit and Cobertura. To build and run the initial tests, open a Command Prompt window, change to the new directory, and type:
C:\coverage> .\bin\antAnt should create the appropriate output directories, compile the program, instrument it, run the JUnit tests, and generate a report. When it finishes, open the file reports\index.html in a web browser to see the code coverage report. Click on the Tree class in the left pane to see exactly which lines were and were not executed by the JUnit test.
Your assignment is to create new JUnit tests to reach 100% code coverage. After adding each new test, re-run Ant and reload the report to see the results.
A number of other files will be generated by Ant as part of the build process:
- The build instructions for Ant. Think of Ant as a Java-specific version of make, and build.xml as its Makefile
- The batch file used to run Ant.
- This directory contains .JAR files required by Ant, JUnit, and Cobertura.
- The Binary Tree class that you will be testing. This is an example program from a compiler class at UCLA.
- The JUnit test suite. This is the file you will need to modify in order to add tests.
- This directory contains compiled .class files
- This directory contains .class files with instrumentation added by Cobertura
- This directory contains the HTML files for the coverage report