Code Coverage for Integration tests using Jacoco

帅比萌擦擦* 提交于 2020-01-06 06:19:26

问题


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?


回答1:


Make sure that you use proper JAR file.

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 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 :

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
...

so its filename is 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

and both have Premain-Class attribute

$ unzip lib/jacocoagent.jar

$ cat META-INF/MANIFEST.MF | grep Premain
Premain-Class: org.jacoco.agent.rt.internal_c13123e.PreMain


来源:https://stackoverflow.com/questions/53644625/code-coverage-for-integration-tests-using-jacoco

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!