Notes on making Cobertura work

I'd rather use Emma, because integration with Eclipse is cleaner. However, I did experiement some with Cobertura. I eventually removed it from the checked in code, but I want to save it here in case it's useful later.

        <path id="cobertura.classpath">
                <fileset dir="${cobertura.dir}">
                        <include name="cobertura.jar" />
                        <include name="lib/**/*.jar" />
                </fileset>
        </path>
        
        <taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
        
    <target name="run-coburtura" description="Runs the Coburtura code coverage tool" >
                <delete dir="${target.dir}" />
                
                <mkdir dir="${instrumented.dir}" />
                <mkdir dir="${test.results.dir}" />
                
                <antcall target="compile">
                        <param name="debug" value="true" />
                </antcall>
                
                <cobertura-instrument todir="${instrumented.dir}">
                        <ignore regex="org.apache.log4j.*" />
                        <fileset dir="${classes.dir}">
                                <include name="**/*.class"/>
                        </fileset>
                </cobertura-instrument>
                
                <junit>
                        <classpath refid="jar.classpath" />
                        <classpath location="${instrumented.dir}" />
                        <classpath location="${classes.dir}" />
                        <classpath refid="cobertura.classpath" />
                <formatter type="brief" usefile="false" />
                <formatter type="xml"/>  <!-- generates test results CruiseControl can use -->
                <batchtest haltonfailure="yes" todir="${test.results.dir}" fork="yes">  <!-- fork required to get proper classloader -->
                    <fileset dir="${instrumented.dir}">
                        <include name="**/*Test.class"/>
                    </fileset>
                </batchtest>
            </junit>
                
                <cobertura-report format="html" destdir="${target.dir}/cobertura">
                    <fileset dir="${src.dir}">
                        <include name="**/*.java" />
                    </fileset>
                        <fileset dir="${external.src.dir}">
                        <include name="**/*.java" />
                    </fileset>
                    <fileset dir="${test.src.dir}">
                        <include name="**/*.java" />
                    </fileset>
                </cobertura-report>
        </target>

EclipseCoburtura (last edited 2010-05-28 19:12:38 by KennethPronovici)