是的,这是另一个 0% 覆盖率的东西。我已检查并确认以下内容:
1) ...根据http://cobertura.sourceforge.net/faq.html,该程序确实正在生成适当的 cobertura.ser 文件,并且该文件和 Instrumented 目录的内容已经消失。
2) ...“instrumented”是 Cobertura 测试中确定的第一个类路径。
3) ...这些行确实正在我的测试套件中进行测试,并且...
4) ...确实正在创建并写入“instrumented”目录——我看到了这种情况。
奇怪的是,我注意到 Ant 生成的报告只不过是一系列消息,内容如下:
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)
但是,如果我注释掉所有 Cobertura 引用和目标,测试运行良好,并且 Ant 报告在成功和失败方面给了我 100% 的预期。
我的 build.xml 文件在下面……有什么想法吗???谢谢....
<?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>