在unix中使用Cobertura生成代码覆盖率报告

时间:2013-01-16 04:47:51

标签: java cobertura

我使用cobertura-1.9.4.1生成代码覆盖率报告。首先我将类路径设置为cobertura.jar和lib文件夹中的其他jar。然后我执行cobertura-instrument.sh。 但在执行时,我得到0类的错误加载信息。我给出了编译类的完整路径仍然无法检测类。 那么,我错过了什么或可能是什么原因。

2 个答案:

答案 0 :(得分:0)

您的意思是错误是在检测期间,还是在运行测试后,覆盖率仍显示为零?

这是一个检测示例(使用Ant):

<target name="--coverage.instrument">
    <delete file="cobertura.ser"/>
    <mkdir dir="${coverage.instrumented.dir}"/>
    <cobertura-instrument todir="${coverage.instrumented.dir}">
        <fileset dir="${classes.main.dir}">
            <include name="**/*.class"/>
            <exclude name="**/*Test.class"/>
        </fileset>
    </cobertura-instrument>
</target>

不要忘记在测试时需要这个sysproperty(例如在Ant Junit任务中):

<sysproperty key="net.sourceforge.cobertura.datafile" file="cobertura.ser"/>

一旦建立了Cobertura,就会发生一个仪表,一个执行的例子:

<target name="--test.unit">
    <mkdir dir="${temp.dir}/unit-tests"/>

    <junit forkmode="perBatch" printsummary="yes" haltonfailure="no" haltonerror="no"
           failureproperty="unit.tests.failed">

        <sysproperty key="net.sourceforge.cobertura.datafile" file="cobertura.ser"/>
        <classpath refid="classpath.test.utest"/>
        <formatter type="xml"/>

        <batchtest fork="yes" todir="${temp.dir}/unit-tests">
            <fileset dir="${java.src.utest.dir}" includes="**/*Test.java"/>
        </batchtest>
    </junit>

</target>

答案 1 :(得分:0)

我认为最近版本的Cobertura与JDK5不兼容。强烈建议升级JDK。

相关问题