In Cobertura Report all the percentages are 0 and message is coming have you mentioned the correct path

Here is my build.xml. Here all the paths are mentioned.

In report all the percentages are 0(ZERO). And It is also prompting me that "Have you mentioned the specified source directory"

Please suggest where is the mistake. Either I have to change the build.xml or have to perform some steps. First I ran all the junit test cases, then stoped the server and then run the build.xml as ant-build.

<project name="RFM2" default="cobertura_REPORT">
    <property name="BASEDIR" value="D:/SIT/busnessservice" />
    <property name="cobertura.dir" value="D:/SIT/JUNIT_jars/cobertura-1.9.1" />
    <property name="src.dir" value="${BASEDIR}/src" />
    <property name="build.dir" value="${BASEDIR}/build" />
    <property name="dist.dir" value="${BASEDIR}/dist" />
    <property name="lib.dir" value="D:/SIT/JUNIT_jars/jars" />
    <property name="report.dir" value="${BASEDIR}/reports" />
    <property name="cobertura.ser.file" value="${cobertura.dir}/cobertura.ser" />
    <property name="server.ser.file" value="D:/Program Files/cobertura.ser" />
    <property name="instrumentedDir" value="${cobertura.dir}/instrument" />
    <property name="junit.data.dir" value="${report.dir}/junit/data" />
    <property name="junit.report.dir" value="${report.dir}/junit/html" />  
    <property name="junit.dir" value="D:/SIT/JUNIT_jars/jars" />    
    <property name="test.dir" value="D:/SIT/JUNITTESTFILES" />

    <!--class path for cobertula --> 

    <path id="cobertura.classpath">
        <fileset dir="${cobertura.dir}">
            <include name="cobertura-1.9.4.1.jar" /> 
            <include name="*.jar" />
        </fileset>
    </path>

    <!--class path for JUNIT -->

    <path id="junit.classpath">
        <fileset dir="${junit.dir}">
            <include name="**/*.jar" />
        </fileset>
        <pathelement location="${junit.dir}/junit-4.1.jar" />
        <pathelement location="${BASEDIR}/bin" />
        <path refid="cobertura.classpath" />
    </path>

    <taskdef classpathref="cobertura.classpath" resource="tasks.properties" />

    <!-- PATH FOR LIB -->
    <path id="lib.classpath">
        <fileset dir="${lib.dir}" includes="*.jar" />
    </path>


    <path id="runtime.classpath">
        <pathelement location="${build.dir}" />
        <path refid="lib.classpath" />
    </path>

    <!--Initialization -->
    <target name="init">
        <mkdir dir="${dist.dir}" />
    </target>

    <!-- Clean files-->
    <target name="clean" description="Remove all generated files.">
        <delete dir="${build.dir}" />
        <delete dir="${dist.dir}" />
    </target>
    <!-- Compile the java file -->



    <!--Instrument the files -->
    <target name="cobertura_instrument">




    <cobertura-instrument todir="${instrumentedDir}" datafile="${server.ser.file}">
            <fileset dir="${lib.dir}">
                <include name="businessServices.jar" />
            </fileset>
        </cobertura-instrument>
        <!-- Copy cobertula.ser file in server-->

    </target>

    <!--copy the instrumented file in class file-->

I have removed this block as I think it is not getting used . But still my report is getting generated with zero percentage.

    <!--Make EAR-->
    <target name="making ear">
        <echo>come in making ear</echo>
        <ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
            <fileset dir="${build.dir}" includes="*.jar,*.war" />
        </ear>
    </target>

    <!--Run the JUNIT Test Case-->

    <target name="runJunitTest">
        <junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
            <!--
            Specify the name of the coverage data file to use.
            The value specified below is the default.
        -->
            <sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
            <classpath location="${instrumentedDir}" />
            <classpath refid="junit.classpath" />
            <classpath refid="cobertura.dir" />
            <formatter type="plain" usefile="false" />
            <formatter type="xml"/>
            <test name="${test.dir}/ColorConfigurationTest" />
            <batchtest todir="${report.dir}" unless="testcase">
                    <fileset dir="${test.dir}">
                        <include name="**/*Test.java" />
                    </fileset>
                </batchtest>
        </junit>
    </target>

    <!--rEPORTING-->

    <target name="cobertura_REPORT">
        <delete dir="${report.dir}" />
        <mkdir dir="${report.dir}" />
        <cobertura-report srcdir="${src.dir}" format="html" destdir="${report.dir}"  datafile="${server.ser.file}">
        </cobertura-report>
    </target>
</project>


<!--Make EAR-->
    <target name="making ear">
        <echo>come in making ear</echo>
        <ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
            <fileset dir="${build.dir}" includes="*.jar,*.war" />
        </ear>
    </target>

    <!--Run the JUNIT Test Case-->

    <target name="runJunitTest">
        <junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
            <!--
            Specify the name of the coverage data file to use.
            The value specified below is the default.
        -->
            <sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
            <classpath location="${instrumentedDir}" />
            <classpath refid="junit.classpath" />
            <classpath refid="cobertura.dir" />
            <formatter type="plain" usefile="false" />
            <formatter type="xml"/>
            <test name="${test.dir}/ColorConfigurationTest" />
            <batchtest todir="${report.dir}" unless="testcase">
                    <fileset dir="${test.dir}">
                        <include name="**/*Test.java" />
                    </fileset>
                </batchtest>
        </junit>
    </target>

Answers


I noticed one thing that should be easy to correct - that doesn't match the Cobertura doc or my working copy. Hopefully this will fix your problem.

Your JUnit task references <classpath refid="cobertura.dir" /> but the cobertura.dir is not a path id, it is the name of a property pointing to your cobertura directory. (IntelliJ IDEA flagged it in red, which caught my eye!)

In my script, I have:

Then my JUnit task references the cobertura.classpath like so:

<classpath refid="cobertura.classpath" />

Hope this helps!


Need Your Help

swift: "for" loop and "if" statement return four arrays with one element instead of one array with four elements

ios arrays swift loops if-statement

I have an array of NSDate. I am filtering this array with a timeIntervalSinceDate to only keep specific ones. After looping through the array, and submitting an "if" statement to compare the elemen...

Is it possible to know when a credit card transaction hits the bank account?

payment-gateway payment-processing

I'm building a payment dispursement system; There are plenty of API's from different providers to do ACH transactions to transfer money from one bank account to another, and payment gateways to cha...