0
votes

These are the steps that create the error:

  1. Run my unit tests within Eclipse (Cntrl-F11). All 67 succeed and report as such.
  2. Using an Ant build.xml file, run a Cobertura task to generate a coverage report. The task fails stating that a unit test has failed.
  3. When I try to run the unit tests using Eclipse again, I receive the following error:

Unsupported major.minor version 51.0

(These symptoms persist until I use Project -> Clean within Eclipse.)

My Cobertura ant task is:

<target name="report-test" description="Generate a test coverage report." depends="clean, compile">
        <taskdef resource="tasks.properties">
            <classpath>
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/cobertura.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/asm-3.0.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/asm-tree-3.0.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/log4j-1.2.9.jar" />
                <pathelement location="${lib.dir}/cobertura-1.9.4.1/lib/jakarta-oro-2.0.8.jar" />
            </classpath>
        </taskdef>
        <cobertura-instrument todir="${build.dir}/cobertura-instrument">
            <fileset dir="${build.dir}">
                <include name="**/*.class"/>
            </fileset>
        </cobertura-instrument>
        <junit printsummary="yes" fork="true" haltonfailure="yes" showoutput="yes">
            <classpath location="${build.dir}/cobertura-instrument"/>
            <classpath location="${build.dir}"/>
            <classpath refid="classpath.test" />
            <sysproperty key="net.sourceforge.cobertura.datafile" file="cobertura.ser"/>
            <formatter type="xml" />
            <batchtest todir="doc/junit">
                <fileset dir="${test.dir}" />
            </batchtest>
        </junit>
        <cobertura-report srcdir="${src.dir}" destdir="doc/coverage" format="xml" />
        <delete file="cobertura.ser"/>
    </target>
1

1 Answers

2
votes

Coberatura hasn't switched Eclipse's Java version.

What it has actually done is recompile the classes using a version of Java that is more recent than the one you are using to run Eclipse. Eclipse can't load those .class files.

The short term solution is to get Eclipse to clean and rebuild the project(s) after running Coberatura ... as you are currently doing.

In the long term, you should either change Eclipse to run using the same Java version as your Ant builds, or change the Ant build file so that it doesn't write the ".class" files into the Eclipse workspace. Or both ... 'cos having something else writing stuff into the Eclipse workspace is going to cause other problems too.