How do I use Clover with NetBeans?

Clover can be used with NetBeans 6.1 by integrating Clover for Ant into your NetBeans project build, which is Ant-based. This integration will allow seamless instrumentation, test execution and hard-copy coverage report generation from within NetBeans.

To start, download Clover for Ant at Once you've downloaded Clover for Ant, expand it to a separate folder (referred to as CLOVER_HOME).

1. Add Clover to the NetBeans Ant

1.1 Go to Preferences->Miscellaneous->Ant and use Add JAR/ZIP to add CLOVER_HOME/lib/clover.jar to the classpath.

2. Create a new Clover Library

2.1 Open Tools/Libraries

2.2 Click "New Library..." and name it "Clover"

2.3 Add CLOVER_HOME/lib/clover.jar to the new library.

3. Use Add JAR/Folder to add CLOVER_HOME/lib/clover.jar to the project classpaths

3.1 Open Project/Properties...

3.2 In Libraries add the Clover library to the Compile, Run, Compile tests, Run tests classpaths

4. Add Clover targets to the build

4.1 Add the following to the project build.xml (go to Files view and edit this file)

<target name="-pre-init" depends="with.clover"/>
<target name="-post-clean" depends="clover.clean"/>

<property name="clover.enable" value="on"/>
<property name="clover.reportdir" value="clover_html"/>

<taskdef resource="cloverlib.xml"/>

<target name="with.clover" if="clover.enable">

<target name="" depends="-pre-init">
        <current outfile="${clover.reportdir}">
            <format type="html"/>

<target name="clover.clean">

5. Using Clover from within NetBeans

5.1 Perform a complete clean and rebuild of the project by selecting Build->Clean and Build Main Project...

5.2 Select the project build.xml and run the test target using the Ant Targets window

5.3 Run the target to generate a Clover HTML report

5.4 The clover.enable can be used to disable Clover integration

5.5 The clover.reportdir can be used to control where the HTML report is generated

6. Extending the Clover integration

Because NetBeans uses a standard Ant-based build, you can use all of Clover's Ant tasks from your project build file. This allows you to control includes and excludes, set up source-level filters, change report formats and more. For an overview of the Clover Ant tasks, see Ant Task Reference.