当前位置 : 首页 » 文章分类 :  开发  »  JaCoCo

JaCoCo

JaCoCo 笔记

JaCoCo Java Code Coverage Library
https://www.jacoco.org/jacoco/

jacoco / jacoco
https://github.com/jacoco/jacoco


jacoco的两种插桩方式

On-the-fly插桩

JVM中通过 -javaagent 参数指定特定的 jar 文件启动 Instrumentation 的代理程序,代理程序在通过 Class Loader 装载一个 class 前判断是否转换修改class文件,将统计代码插入class,测试覆盖率分析可以在JVM执行测试代码的过程中完成。

Offline模式

在测试前先对文件进行插桩,然后生成插过桩的class或jar包,测试插过桩 的class和jar包后,会生成动态覆盖信息到文件,最后统一对覆盖信息进行处理,并生成报告。


JaCoCo Maven Plugin

Maven Plug-in
https://www.eclemma.org/jacoco/trunk/doc/maven.html

<dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.3</version>
</dependency>

Error while instrumenting javax/script/ScriptEngineFactory

jacoco 报错如下:

java.lang.instrument.IllegalClassFormatException: Error while instrumenting javax/script/ScriptEngineFactory.
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: java.io.IOException: Error while instrumenting javax/script/ScriptEngineFactory.
        ... 46 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 58
        ... 47 more
java.lang.instrument.IllegalClassFormatException: Error while instrumenting javax/script/ScriptEngineManager$1.
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: java.io.IOException: Error while instrumenting javax/script/ScriptEngineManager$1.
        ... 47 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 58

原因:
同时装有 maven-surefire-plugin 和 jacoco-maven-plugin 插件
Jacoco maven plugin clogs up logs with Exceptions #32
https://github.com/jacoco/jacoco/issues/32

解决:
配置 maven-surefire-plugin 跳过测试就好了


上一篇 Base64

下一篇 Apache-Commons-Codec 笔记

阅读
评论
478
阅读预计2分钟
创建日期 2020-10-22
修改日期 2020-10-22
类别

页面信息

location:
protocol:
host:
hostname:
origin:
pathname:
href:
document:
referrer:
navigator:
platform:
userAgent:

评论