ScatteredFrog
ScatteredFrog

Reputation: 71

Cobertura reporting 0% coverage despite meeting the requirements to work

Yeah, this is another one of those 0% coverage things. I have checked and confirmed the following:

1) ...that the program is indeed generating the appropriate cobertura.ser file and that that file and the contents of the Instrumented directory are gone, as per http://cobertura.sourceforge.net/faq.html.

2) ...that "instrumented" is the first classpath identified in the Cobertura test.

3) ...that the lines are indeed being tested in my test suite, and...

4) ...that the "instrumented" directory is indeed being created and written to -- I watched that happen.

What's weird is that I noticed that the report that Ant generates is nothing but a series of messages that read:

Testcase: pluralizeIt[0] took 0.004 sec
    Caused an ERROR
Instruction type does not match stack map in method StringUtil.main([Ljava/lang/String;)V at offset 50
java.lang.VerifyError: Instruction type does not match stack map in method StringUtil.main([Ljava/lang/String;)V at offset 50
    at PluralTest.pluralizeIt(PluralTest.java:55)

But if I comment out all the Cobertura references and targets, the test runs fine, and the Ant report gives me 100% what I expect in terms of successes and failures.

My build.xml file is below...any thoughts??? Thanks....

<?xml version="1.0" encoding="UTF-8"?>
<project name="TestPlurazliation" default="coverage" basedir=".">
    <property name="src" location="src" />
    <property name="build" location="bin" />
    <property name="cobertura" location="/Users/Dauber/Desktop/cobertura-1.9.4.1" />
    <property name="instrumented" location="instrumented" />
    <property name="coverage.xml" location="coverage-xml" />
    <property name="coverage.html" location="coverage-html" />
    <path id="cobertura.classpath">
        <fileset dir="${cobertura}">
            <include name="cobertura.jar" />
            <include name="lib/**/*.jar" />
        </fileset>
    </path>

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

    <target name="init">
        <tstamp />
        <mkdir dir="${build}" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="/Volumes/Junk/Java projects/SE433/TestingPluralization/src" includeantruntime="false" debug="on" destdir="${build}">
            <classpath location="/Users/Dauber/Desktop/junit-4.10.jar" />
        </javac>
    </target>

    <target name="PluralizationTest" depends="compile">
        <junit printsummary="yes" fork="yes" haltonfailure="yes">
            <classpath location="/Users/Dauber/Desktop/junit-4.10.jar" />
            <classpath location="${build}" />
            <formatter type="plain" />
            <test name="PluralTest" />
        </junit>
    </target>

    <target name="instrument" depends="init,compile">
        <delete file="cobertura.ser" />
        <delete dir="${instrumented}" />
        <cobertura-instrument todir="${instrumented}">
            <ignore regex="org.apache.log4j.*" />
            <fileset dir="bin">
                <include name="**/*.class" />
                <exclude name="**/*Test*.class" />
            </fileset>
        </cobertura-instrument>
    </target>

    <target name="PluralizationTest2" depends="init,compile">
        <junit fork="yes">
            <classpath location="${instrumented}" />
            <classpath location="${build}" />
            <classpath location="/Users/Dauber/Desktop/junit-4.10.jar" />
            <classpath refid="cobertura.classpath" />
            <formatter type="plain" />
            <test name="PluralTest" />
        </junit>
    </target>

    <target name="coverage-report-xml">
        <cobertura-report srcdir="${src}" destdir="${coverage.xml}" format="xml" />
    </target>

    <target name="coverage-report-html">
        <cobertura-report srcdir="${src}" destdir="${coverage.html}"/>
    </target>

    <target name="coverage" depends="compile,instrument,PluralizationTest2,coverage-report-xml,coverage-report-html"  />

    <target name="clean" description="clean up" >
        <delete dir="${build}"/>
        <delete dir="${instrumented}"/>
    </target>

</project>

Upvotes: 3

Views: 3838

Answers (1)

brandonjsmith
brandonjsmith

Reputation: 246

If you're using JDK 7, you need to add the UseSplitVerifier JVM argument:

<jvmarg value="-XX:-UseSplitVerifier"/>

(Note: I'm adding this as an answer from the comments so others can easily find the solution.)

Upvotes: 5

Related Questions