使用Jacoco进行集成测试的代码覆盖率 [英] Code Coverage for Integration tests using Jacoco
问题描述
我将版本0.8.1的jacocoagent.jar
作为Java代理传递,以将服务器上的代码覆盖率记录到我的服务器启动脚本中.但是我发现jar中缺少Pre-main class属性,结果出现以下错误:
I am passing jacocoagent.jar
of version 0.8.1 as a java agent to record the code coverage on the server to my server start-up script. But I see that Pre-main class attribute is missing in the jar, as a result, I get the following error:
Error occurred during initialization of VM
Failed to find Premain-Class manifest attribute in
/u01/jetty_home/jacoco/jacocoagent.jar
agent library failed to init: instrument.
有人对如何解决这个问题有想法吗?
Does anyone have thoughts on how to fix this?
推荐答案
确保使用正确的JAR文件.
Make sure that you use proper JAR file.
lib/jacocoagent.jar
具有以下校验和>
lib/jacocoagent.jar
in jacoco-0.8.1.zip
that is linked from JaCoCo homepage has following checksums
$ wget http://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.1/jacoco-0.8.1.zip
$ unzip jacoco-0.8.1.zip
$ md5sum lib/jacocoagent.jar
2873d7006dc9672d84981792df2c5b7a lib/jacocoagent.jar
$ sha256sum lib/jacocoagent.jar
cd40d1c1aea4112adb82049df3f462b60380ce1bb00bdecb1cfdb862e34be8dd lib/jacocoagent.jar
JaCoCo主页还包含 JaCoCo文档上的链接,该文档包含页面"Maven存储库" ,并解释为Maven Central存储库中的工件完全相同groupId org.jacoco
,artifactId org.jacoco.agent
,最重要的是分类器runtime
:
JaCoCo homepage also contains link on JaCoCo documentation, which contains page "Maven Repository" with explanation that exactly the same artifact in Maven Central Repository has groupId org.jacoco
, artifactId org.jacoco.agent
and most importantly classifier runtime
:
以下JAR文件可用:
Following JAR files are available:
Group ID | Artifact ID | Classifier | Description
-----------+------------------+------------+-------------
...
org.jacoco | org.jacoco.agent | | API to get a local copy of the agent
org.jacoco | org.jacoco.agent | runtime | Agent
...
,因此其文件名为 org.jacoco.agent-0.8.1-runtime.jar
$ wget http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.1/org.jacoco.agent-0.8.1-runtime.jar
$ md5sum org.jacoco.agent-0.8.1-runtime.jar
2873d7006dc9672d84981792df2c5b7a org.jacoco.agent-0.8.1-runtime.jar
$ sha256sum org.jacoco.agent-0.8.1-runtime.jar
cd40d1c1aea4112adb82049df3f462b60380ce1bb00bdecb1cfdb862e34be8dd org.jacoco.agent-0.8.1-runtime.jar
都具有Premain-Class
属性
$ unzip lib/jacocoagent.jar
$ cat META-INF/MANIFEST.MF | grep Premain
Premain-Class: org.jacoco.agent.rt.internal_c13123e.PreMain
这篇关于使用Jacoco进行集成测试的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!