Home | Forums

Adding Clover.NET Operations

Adding Clover.NET to your project

There are two approaches to adding Clover.NET to your existing NAnt-based build system. You can either add Clover.NET targets to your main build file or you can create a separate build file to manage just the Clover.NET related tasks. Both approaches are valid.

Updating your build file

When you add Clover.NET to your build file, we recommend the following steps:

  1. Add the <loadtasks> call at the top of your build

                <loadtasks assembly="${Clover.home}\CloverNant-0.85.dll"/>
              
  2. Add a target, "with-clover" for enabling Clover.NET instrumentation

                <target name="with-clover">
                  <clover-setup initstring="CloverBuild\clover.cdb" 
                                builddir="CloverBuild" 
                                flatten="true"/>
                </target>
              
  3. Add a clover-report target to generate reports. Note the dependency between the report target and the with-clover target. This ensures the report target knows where the Clover.NET coverage database is located.

                <target name="clover-report" depends="with-clover">
                    <clover-report>
                      <current title="test" output="report">
                        <format type="html"/>
                      </current>
                    </clover-report>
                </target>
              

With the above changes in place you can continue to use your build file as before for normal builds. To build with Clover, you specify the with-clover target:

NAnt with-clover dist

For reports, you use the clover-report target. If you wish, you can add more dependencies to the clover-report target to build and run tests with the Clovered build.

Auxilliary Build File

The other approach to adding Clover.NET to your project is to create an auxilliary build file with just the Clover.NET related targets. Your main build file is left as is.

        <project default="build">
          <echo message="building with Clover"/>
          <property name="Clover.home" value="Install Directory"/>
          <loadtasks assembly="${Clover.home}\CloverNant-0.85.dll"/>
          <clover-setup initstring="CloverBuild\clover.cdb" 
                        builddir="CloverBuild" 
                        flatten="true"/>
          <target name="build">                  
            <nant buildfile="main.build"/>
          </target>
          <target name="report">
            <clover-report>
              <current title="test" output="report">
                <format type="html"/>
              </current>
            </clover-report>
          </target>
        </project>      
      

As shown in the example, the clover.build build file enables Clover for all operations. For build operations it delegates to your main.build build file, which will Instrument code prior to compilation.