Home | Clover | Clover.NET | FishEye | Support | Account | Download | Buy Now

Using Clover with Ant and JUnit

This tutorial demonstrates how you can use Clover with JUnit to measure the code coverage of a project. It takes you through the process of compiling a sample project and running the unit tests from Ant, then modifying the build file to add Clover targets and properties. It is split into three parts covering Current Reports, Historical Reports and Advanced Features.

The Clover Tutorial describes different features of Clover in a step-by-step approach. Once you've completed the Tutorial, have a look at Using Clover Interactively and Using Clover in Automated builds for examples of how to pull the different aspects of Clover together for your project.

Before you start

You will need Clover, Ant and JUnit installed on your system, preferably the latest versions.

Instructions for installing Ant can be found in the Apache Ant User Manual.

Instructions for installing Clover can be found in the Installation Options section.

For instructions on installing JUnit consult the JUnit website. To allow JUnit to work with Ant, you must also copy <JUNIT_HOME>/junit.jar into <ANT_HOME>/lib.

The Clover tutorial assumes that you have basic knowledge of creating and modifying Ant build files. The Apache Ant User Manual provides any additional support you may require in this area. It is also assumed that you have a basic understanding of JUnit. A good introduction to JUnit can be found in the JUnit Cookbook. This Clover tutorial is crafted around the example code described in the Cookbook.

The tutorial work area

The source files for this tutorial are located in the standard Clover distribution, under the 'tutorial' directory. In the 'tutorial' directory you will find the initial build file and the directory 'src' which contains the java files that you will be testing. These sample files are shipped with JUnit and described in the JUnit Cookbook. They represent a simple library for dealing with money and provide methods to add, subtract, and collect money etc. The MoneyTest.java file contains all the unit tests for the library and utilises the JUnit framework.