Cobertura 1.9.2的代码覆盖率为零,但测试正常 [英] Zero code coverage with cobertura 1.9.2 but tests are working

查看:93
本文介绍了Cobertura 1.9.2的代码覆盖率为零,但测试正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行代码覆盖率目标:

I run the code coverage target:

<junit fork="yes" dir="${basedir}" failureProperty="test.failed">
        <!--
                        Note the classpath order: instrumented classes are before the
                        original (uninstrumented) classes.  This is important.
                -->
        <classpath path="${instrumented.dir}" />
        <classpath path="${classes.dir}" />
        <classpath refid="classpath" />
        <!--
                        The instrumented classes reference classes used by the
                        Cobertura runtime, so Cobertura and its dependencies
                        must be on your classpath.
                -->
        <classpath refid="cobertura.classpath" />

        <formatter type="xml" />
        <!--<test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />-->
        <batchtest fork="yes" todir="${reports.xml.dir}">
                <fileset dir="${classes.dir}">
                        <include name="**/generated/AllTests.class" />
                </fileset>
        </batchtest>
</junit>

<junitreport todir="${reports.xml.dir}">
        <fileset dir="${reports.xml.dir}">
                <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="${reports.html.dir}" />
</junitreport>

然后我得到以下输出(使用fork = true时):

Then I get the following output ( when using fork="true"):

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at net.sourceforge.cobertura.util.FileLocker.lock(FileLocker.java:124)
        at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:331)
        at net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:31)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.io.IOException: No locks available
        at sun.nio.ch.FileChannelImpl.lock0(Native Method)
        at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:784)
        at java.nio.channels.FileChannel.lock(FileChannel.java:865)
        ... 8 more
---------------------------------------
Unable to get lock on /vobs/rnc/rrt/roam2/roamSs/RoamMao_swb/RoamMao_bldu/ant_build/cobertura.ser.lock: null
This is known to happen on Linux kernel 2.6.20.
Make sure cobertura.jar is in the root classpath of the jvm 
process running the instrumented code.  If the instrumented code 
is running in a web server, this means cobertura.jar should be in 
the web server's lib directory.
Don't put multiple copies of cobertura.jar in different WEB-INF/lib directories.
Only one classloader should load cobertura.  It should be the root classloader.

我正在使用Ant 1.7.0和cobertura 1.9.2。

I am using Ant 1.7.0 and cobertura 1.9.2.

为什么没有保险?如我在目标中所见,测试运行正常。
我尝试切换Java版本(1.5.0_06和1.6.0_10),但没有区别。

Any ideas why there is no coverage? Test run ok as I see in my target. I have tried to switch java versions ( 1.5.0_06 and 1.6.0_10) but no difference.

推荐答案

I发现成功设置了环境属性 cobertura.use.java.nio = false

I found success in setting the environment property cobertura.use.java.nio=false.

自从我使用ant以来,我只是通过将以下内容添加到 cobertura-build.xml 文件中< junit> 命令:

Since I was using ant, I just edited the cobertura-build.xml file by adding the following to the <junit> command:

<junit fork="yes">
  <jvmarg value="-Dcobertura.use.java.nio=false"/>
  ...
</junit>

这篇关于Cobertura 1.9.2的代码覆盖率为零,但测试正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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