当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Using Cobertura in unix to generate the code coverage reports

问题描述:

I m using cobertura-1.9.4.1 to generate code coverage reports.First I set the classpath to cobertura.jar and to other jars in the lib folder. Then I execute cobertura-instrument.sh.

But on executing I get the error loaded information on 0 classes . I m giving the complete path to the compiled classes still it is unable to instrument the classes .

So, what am I missing or what could be the possible reasons for this.

网友答案:

Do you mean the error is during the instrumentation, or that after running your tests, the coverage still shows zero?

Here's an example of instrumentation (with 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>

Don't forget that you need this sysproperty when testing (eg in Ant Junit task):

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

Once Cobertura is set up an instrumentation has happened, an example of execution:

<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>
网友答案:

I believe that recent versions of Cobertura don't work well with JDK5. Strongly suggest upgrading the JDK.

分享给朋友:
您可能感兴趣的文章:
随机阅读: