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.
If you want to quickly see exemplary Clover report and not be bothered by manual configuration, please have a look at:
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.
You will need to download Clover-for-Ant and Apache Ant, preferably the latest versions, then install them on your system. The tutorial source files and JUnit are bundled with the Clover distribution in the /tutorial directory.
Instructions for installing Ant can be found in the Apache Ant User Manual.
Instructions for installing Clover can be found in the Clover-for-Ant Installation Guide.
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 source files are located within the 'tutorial' directory (that is, CLOVER_HOME/tutorial
). 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 test files, as 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.
The build.xml
file is located directly under the 'tutorial' directory.
Once you have Ant installed and the Clover for Ant package have been downloaded, you are ready to progress to Part 1 - Measuring Coverage in the tutorial.