Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach JaCoCo Agent to application server

I am using JBoss and running Selenium tests from Jenkins. I want to measure code coverage from Selenium tests, so apparently I should attach the JaCoCo java agent to the server. I have done like this:

./run.sh -c Default -Djavaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec

However, no output file is ever generated. I am here pointing to jacocoagent.jar in the Jenkins path, but is it so that the jacocoagent.jar and jacoco.exec must be in the actual server path, not Jenkins?

like image 571
user1340582 Avatar asked Dec 19 '12 12:12

user1340582


People also ask

How do I add JaCoCo agent to JVM?

To attach the JaCoCo agent, append the following JaCoCo options to the catalina.sh (Linux) / catalina. bat (Windows) file available inside Jacoco's bin directory. JaCoCo agent is successfully attached to JVM now.

How does JaCoCo agent work?

JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a so called Java agent. This mechanism allows in-memory pre-processing of all class files during class loading independent of the application framework.

How do I add JaCoCo?

To get started, apply the JaCoCo plugin to the project you want to calculate code coverage for. If the Java plugin is also applied to your project, a new task named jacocoTestReport is created. By default, a HTML report is generated at $buildDir/reports/jacoco/test .

How do I run JaCoCo code coverage?

To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By integrating the JaCoCo plugin, the results of the code coverage analysis can be reviewed as an HTML report. The current version of the JaCoCo-Maven plugin can be downloaded from the MVN Repository.


1 Answers

The javaagent needs to be passed as a VM option like this :

-javaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec

You are passing it as a system property (using -D).

You can pass VM options to the Jboss application server through a JAVA_OPTS environment variable. (the run.sh will pick it up if the JAVA_OPTS is exported before running the run.sh script). Something like this should do :

export JAVA_OPTS="$JAVA_OPTS -javaagent:[path to Jenkins workspace]/tools/libs/jacocoagent.jar=destfile=[path to Jenkins]/jacoco.exec"
./run.sh

More information on the javaagent configuration can be found here :

http://www.eclemma.org/jacoco/trunk/doc/agent.html

like image 108
ddewaele Avatar answered Oct 03 '22 08:10

ddewaele