Cobertura显示0%覆盖率 [英] Cobertura showing 0% coverage

查看:96
本文介绍了Cobertura显示0%覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Cobertura 1.9.3与NetBeans 6.8,Ant 1.7.1和JDK 1.6.0_21一起使用-WAR,并进行EJB,JUnit 4测试.

I'm using Cobertura 1.9.3 with NetBeans 6.8, Ant 1.7.1 and JDK 1.6.0_21 running with -WAR, and EJB, JUnit 4 tests.

当我将行pathelement location="${build.classes.dir}" /更改为pathelement location="${build.test.classes.dir}" /时,有一定的覆盖范围(尽管在错误的类中,它不应该在testclass中,只是为了表明环境和.jar位置设置正确)显示在html报告中.

When I change the line pathelement location="${build.classes.dir}" / to pathelement location="${build.test.classes.dir}" /, there is some coverage (albeit in the wrong classes, it shouldn't be in the testclass, just to show that the environment and .jar locations are set correctly) shown in the html reports.

但是,当我将其更改回pathelement location="${build.classes.dir}" /时,覆盖率始终为0%.

However, when I change it back to pathelement location="${build.classes.dir}" /, I always get 0% coverage.

最后,当检测文件夹确实包含${build.instrumented.dir}中的检测类时(这些类比${build.classes.dir}位置中的类稍大).是的,我从上次运行中删除cobertura.ser后重试.

fwiw, when the instrumentation folders do contain instrumented classes in ${build.instrumented.dir} (these classes are slightly larger than the ones in the ${build.classes.dir} location). And yes, I've retried after deleting cobertura.ser from the previous run.

请问出什么毛病了吗?

干杯

-ejb文件夹中build.xml的代码段.

           <property environment="env"/>
           <path id="cobertura.class.path">
               <fileset dir="${build.dir}/../../lib">
                   <include name="**/*.jar"/>
               </fileset>
           </path>
           <taskdef classpathref="cobertura.class.path" resource="tasks.properties"/>

           <target name="-pre-compile-test">
               <delete dir="${build.instrumented.dir}" />
               <delete dir="${build.report.cobertura.dir}" />
               <mkdir dir="${build.instrumented.dir}" />
               <mkdir dir="${build.report.cobertura.dir}" />
               <cobertura-instrument todir="${build.instrumented.dir}" classpathref="cobertura.class.path">
                   <ignore regex="org.apache.log4j.*" />
                   <includeClasses regex=".*" />
                   <excludeClasses regex=".*\.Test.*" />
                   <excludeClasses regex=".*\.TestSuite.*" />

                   <instrumentationClasspath>
                       <pathelement location="${build.classes.dir}" />
                   </instrumentationClasspath>
               </cobertura-instrument>
           </target>

           <target name="-post-test-run">
               <cobertura-report format="html" srcdir="${src.dir}" destdir="${build.report.cobertura.dir}"/>
               <cobertura-report format="xml" srcdir="${src.dir}" destdir="${build.report.cobertura.dir}"/>
           </target>

===

我还进行了以下设置:

        ...
        build.test.classes.dir=${build.dir}/test/classes
        build.test.results.dir=${build.dir}/test/results
        build.instrumented.dir=${build.dir}/instrumented
        build.report.dir=${build.dir}/report
        build.report.cobertura.dir=${build.report.dir}/cobertura
        ...
        javac.classpath=\
        ${libs.GlassFish_v3.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}
        ...
        javac.test.classpath=\
        ${javac.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}:\
        ${libs.Libraries_Needed_For_JUnit.classpath}:\
        ${build.instrumented.dir}:\
        ${build.classes.dir}:\
        ${libs.junit_4.classpath}
        ...
        run.test.classpath=\
        ${javac.test.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}:\
        ${libs.Cobertura.classpath}:\
        ${libs.Libraries_Needed_For_JUnit.classpath}:\
        ${libs.junit_4.classpath}:\
        ${build.test.classes.dir}
        ...
        src.dir=${source.root}/java
        test.src.dir=test

推荐答案

获得0%覆盖率的唯一情况是

The only case when you get 0% coverage is

  • 如果您没有正确设置类路径,则可以进行测试 针对未检测到的代码运行,或者
  • 您的.ser(元数据)文件已过时,每当您构建/重建代码时,都应删除现有的元数据文件并重新进行检测.
  • When you have not set your classpath correctly, your tests are running against non instrumented code, or,
  • Your .ser (metadata) file is stale, whenever you build/rebuild your code, you should delete the existing metadata file and instrument again.

请参见此处,获取有关类路径的一个很好的示例 https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference

See here for a good example on classpath https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference

同样,将检测类保留在单独的文件夹中,以及为测试类指定其他文件夹也是一个好主意.

Also, it's a good idea to keep instrumented classes in a separate folder, as well as specify a different folder for test classes.

这篇关于Cobertura显示0%覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆