在Cobertura报告中,所有百分比均为0,消息来了,您提到了正确的路径


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

在报告中,所有百分比为0(零)。这也提示我"您是否提到了指定的源目录"

请建议在哪里错误。我必须更改build.xml或必须执行一些步骤。首先,我运行了所有Junit测试用例,然后停止服务器,然后将build.xml作为蚂蚁建造。

<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-->

我删除了此块,因为我认为它没有使用。但是,我的报告仍然以零百分比生成。

    <!--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>

我注意到一件事应该很容易纠正 - 这与Cobertura Doc或我的工作副本不符。希望这能解决您的问题。

您的Junit任务参考<classpath refid="cobertura.dir" />,但Cobertura.dir不是路径ID,它是指向Cobertura目录的属性的名称。(Intellij Idea以红色标记,引起了我的注意!)

在我的脚本中,我有:

然后我的junit任务引用了 cobertura.classpath so:

<classpath refid="cobertura.classpath" />

希望这会有所帮助!

相关内容

最新更新