Do you want to type less code? See the even faster Clover Two Line Integration.

Do you want to try out a ready-to-use code sample? See the Clover Tutorial, Part 0 - Clover in 10 minutes.

Getting started with Clover-for-Ant

This section shows you how to quickly get Clover integrated into your build. Clover instrumentation and reporting are highly configurable so later sections of this manual will detail available configuration options and typical usage scenarios. 

Follow these simple steps to integrate Clover with your build. Unless otherwise indicated, all configuration options throughout this User's Guide apply to both Java and Groovy.

1. Install Clover

See installation guide.

2. Add Clover targets

Edit build.xml for your project:

2.1 Add the Clover Ant tasks to your project:

<taskdef resource="cloverlib.xml"/>

2.2 Add a target to switch on Clover:

<target name="with.clover">
    <clover-setup/>
</target>

2.3 Add one or more targets to run Clover reports:

For HTML reporting, use the following (but change the outdir to a directory path where Clover should put the generated HTML):

<target name="clover.html">
    <clover-html-report outdir="coverage"/>
</target>

OR, for PDF reporting, use the following (but change the outfile to a file where Clover should write the PDF file):

<target name="clover.pdf">
  <clover-pdf-report outfile="coverage.pdf"/>
</target>

OR, for XML reporting, use the following (but change the outfile to a file where Clover should write the XML file):

<target name="clover.xml">
    <clover-report>
       <current outfile="coverage.xml">
          <format type="xml"/>
       </current>
    </clover-report>
</target>

OR, for simple emacs-style reporting to the console, try:

<target name="clover.log">
    <clover-log/>
</target>

2.4 Add clover.jar to the runtime classpath for your tests. How you do this depends on how you run your tests. For tests executed via the <junit> task, add a <classpath> element:

<property name="clover.jar" location="${user.home}/.ant/lib/clover.jar"/>

    <junit ...>
     ...
     <classpath>
         <pathelement path="${clover.jar}"/>
     </classpath>
    <formatter type="xml"/>
</junit>

Compile and run with Clover

Now you can build your project with Clover turned on by adding the "with.clover" target to the list of targets to execute. For example (if your compile target is named 'build' and your unit test target is named 'test'):

ant clean with.clover test

Generate a Coverage Report

To generate a Clover coverage report:

ant clover.html (or clover.xml, clover.pdf etc)

For a sample report, see 'Current' Report.

Next steps

See the Test Optimization Quick Start Guide for Ant, for how to set up Clover's Test Optimization feature to streamline your testing.

Further reading

See Clover for Ant Best Practices.

Troubleshooting

See Clover Knowledge Base Home and Atlassian Community.