【问题标题】:Cobertura reporting 0% coverage despite meeting the requirements to work尽管满足工作要求,Cobertura 仍报告 0% 的覆盖率
【发布时间】:2013-02-17 10:46:54
【问题描述】:

是的,这是另一个 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>

【问题讨论】:

  • 您使用的是 java 7 吗? cobertura 可以与 jdk7 一起使用吗?
  • 我正在使用 JDK 7。我不知道这会是一个问题,但现在你提到它,搜索显示这可能是一个大问题......
  • @ScatteredFrog:你做了更多的研究吗?有什么发现吗?
  • 是的...因为我使用的是 JDK 7,所以我需要添加: 最重要的是,当我添加它时,我忘记了其中一个连字符。 (哦!!!)
  • 好。您可以将其添加为答案。

标签: ant code-coverage junit4 cobertura


【解决方案1】:

如果您使用的是 JDK 7,则需要添加 UseSplitVerifier JVM 参数:

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

(注意:我将其添加为 cmets 的答案,以便其他人可以轻松找到解决方案。)

【讨论】:

猜你喜欢
  • 2015-07-15
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
  • 2011-04-11
  • 1970-01-01
  • 2017-01-03
  • 2010-11-14
  • 1970-01-01
相关资源
最近更新 更多