0

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.

Gora
  • 19
  • 4
nikhil
  • 1

2 Answers2

0

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>
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
  • Well there is an error during instrumentation since there is no change in the cobertura.ser file . The error is that I get the message : Found 2 files to instrument and 0 classes to instrument . The code that I am trying to instrument is compiled java classes . So i m unable to understand why cobertura cannot instrument the code . – nikhil Jan 22 '13 at 09:23
  • Ah, I see. . . I encountered something like that a long time ago, but memory is fuzzy now. . I think it was recent versions of Cobertura didn't like JDK5. . . (so probably irrelevant now). – Jasper Blues Jan 22 '13 at 10:15
  • I m using 1.9.4.1 version and the java code i m trying to instrument is probably developed using jdk5 . So are u saying that there has to be compatibility between cobertura and jdk version we are using. Also is there any relation between the java version and cobertura version i m using.if so which jdk and java version should i be using? – nikhil Jan 22 '13 at 11:08
  • nikhil - Ah, then if my memory was correct that could be it. JDK6 was ok. . . Strongly suggest upgrading, but you could try earlier cobertura as a last resort. – Jasper Blues Jan 22 '13 at 12:47
0

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

Jasper Blues
  • 28,258
  • 22
  • 102
  • 185