记一次代码覆盖率JaCoCo问题排查
java-javaagent:jacocoagent.jar=includes=*,classdumpdir=classes,output=tcpserver,port=6888,address=127.0.0.1
采用这种方式启动tomcat,用于代码覆盖率统计
启动过程中遇到问题,提示:
org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springServiceManager' defined in class path resource [applicationContext.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.cnc.dna.platform.core.SpringServiceManager]: Constructor threw exception; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class ……百度寻求解决方案,看到一个差不多的案例https://blog.csdn.net/kp783491236/article/details/80648063
然后进入了源码分析https://blog.csdn.net/ohcezzz/article/details/78416125
没找到解决方案,下载最新的JaCoCo包也还是一样报错
在认真看报错,有一个"private static transient",于是查找到相关资料https://zhidao.baidu.com/question/422083927.html
http://www.alanzeng.cn/2016/06/eclemma-test-refelect-failed/
==================以上都是废话可以不看================
最后解决了,解决方案是启动命令中的includes参数不用*了,要明确到包,命令改成如下:
java-javaagent:jacocoagent.jar=includes=com.cn.*,classdumpdir=classes,output=tcpserver,port=6888,address=127.0.0.1
【记一次代码覆盖率JaCoCo问题排查】原因是Jacoco 引起反射异常也叫EclEmma引起反射相关测试失败的问题,Jacoco 会利用编译器在编译期间加入 JacocoData成员变量,如果使用反射循环成员变量进而拼凑set或者get方法,会产生NoSuchMethodException,建议在循环中利用isSynthetic()方法检查成员变量(参考https://blog.csdn.net/stanleyw2014/article/details/83414950)
推荐阅读
- CVE-2020-16898|CVE-2020-16898 TCP/IP远程代码执行漏洞
- EffectiveObjective-C2.0|EffectiveObjective-C2.0 笔记 - 第二部分
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 20170612时间和注意力开销记录
- 2018年11月19日|2018年11月19日 星期一 亲子日记第144篇
- 叙述作文
- 2019年12月24日
- 【故障公告】周五下午的一次突发故障
- 人生感悟记#环境仪器宋庆国成长记#072
- 2019.4.18感恩日记