Cobertura avec Script Ant : xml/html rapport de couverture de toujours à 0% de couverture partout

J'ai essayé d'obtenir Cobertura cours d'exécution à l'intérieur de mon script ant. Tout est réussi (source code du bâtiment, junit tests, cobertura rapports (xml /html); mais dans les rapports html, la couverture de code est toujours à 0% ...

Script Ant : faire-instrument

<!-- Make instrument for Cobertura engine -->
<target name="make-instrument">

    <!-- Remove the coverage data file and any old instrumentation. -->
    <delete file="${cobertura.ser}" />

    <!-- Instrument the application classes, writing the instrumented classes into ${build.instrumented.dir}. -->
    <cobertura-instrument todir="${report.cobertura.dir}">

        <!-- The following line causes instrument to ignore any source line containing a reference to log4j, 
                for the purposes of coverage reporting. -->
        <ignore regex="org.apache.log4j.*" />

        <fileset dir="${webcontent.dir}/WEB-INF/classes">
            <!-- Instrument all the application classes, but don't instrument the test classes. -->
            <include name="**/*.class" />
            <exclude name="**/*Test.class" />
        </fileset>

    </cobertura-instrument>

</target>

Script Ant : faire-instrument

<target name="install-cobertura" if="is-hudson-env">        
    <path id="cobertura.classpath">
        <fileset dir="${user.home.sharehunter.dir}/cobertura-${cobertura.rev}">
            <include name="**/cobertura.jar" />
            <include name="**/*.jar" />
        </fileset>
    </path>
    <taskdef resource="tasks.properties" classpathref="cobertura.classpath" />
</target>

Script Ant : junit

<target name="run-tests" depends="make-instrument">

    <path id="classpath.test">
        <path path="${webcontent.dir}/WEB-INF/classes" />
        <pathelement location="${webcontent.dir}/WEB-INF/classes" />
        <fileset dir="${lib.dir}" includes="**/*.jar" />
        <path location="${webcontent.dir}/WEB-INF/classes" />
        <path location="${webcontent.dir}/WEB-INF" />
        <path location="${webcontent.dir}" />
    </path>

    <junit fork="yes" failureProperty="test.failed">

        <classpath refid="classpath.test" />

        <classpath location="${user.home.dir}/junit-${junit.rev}.jar" />

        <!-- Specify the name of the coverage data file to use. 
                The value specified below is the default. -->
        <sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.ser}" />

        <!-- Note the classpath order: instrumented classes are before the original (uninstrumented) classes. -->
        <classpath location="${report.cobertura.dir}" />

        <!--
            The instrumented classes reference classes used by the
            Cobertura runtime, so Cobertura and its dependencies
            must be on your classpath.
        -->
        <classpath refid="cobertura.classpath" />

        <!-- Generate xml files for each junit tests runs -->
        <formatter type="xml" />
        <batchtest todir="${report.junit.dir}">
            <fileset dir="${webcontent.dir}/WEB-INF/classes">
                <include name="**/*Test.class" />
            </fileset>
        </batchtest>

    </junit>

    <!-- Generate Cobertura xml file containing the coverage data -->
    <cobertura-report format="xml" srcdir="${src.main.java.dir}" destdir="${report.cobertura.dir}" datafile="${cobertura.ser}" />

    <!-- Generate Cobertura html file report  containing the coverage data -->
    <cobertura-report format="html" srcdir="${src.main.java.dir}" destdir="${report.cobertura.dir}" datafile="${cobertura.ser}" />

</target>

OriginalL'auteur Anthony | 2010-10-19