ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-cobertura 1.9.2的代码覆盖率为零,但测试正常

2019-10-24 07:11:44  阅读:226  来源: 互联网

标签:code-coverage cobertura java


我运行代码覆盖率目标:

<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”时):

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.

有什么想法为什么没有覆盖?如我在目标中所见,测试运行正常.
我试图切换Java版本(1.5.0_06和1.6.0_10),但没有区别.

解决方法:

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

由于我使用的是ant,因此我通过将以下内容添加到< junit>中编辑了cobertura-build.xml文件.命令:

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

标签:code-coverage,cobertura,java
来源: https://codeday.me/bug/20191024/1919102.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有