I am going to deploy application with JaCoCo agent to production environment to let it work for some time. The result should help me identify the parts of code I can get rid of.
I started some research around the topic and prepared HelloWorld application:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Then I compiled the class: "javac HelloWorld.java" and got HelloWorld.class file.
Now I run the app with the following command: "java -javaagent:jacocoagent.jar HelloWorld" the program executes and jacoco binary is generated. The file contains some binary data.
Everything looks fine but the coverage report shows 0% coverage although it should be 100%.
Has anyone faced this issue or correct me what I am doing the bad way?
I generated full report using this steps. Since I use maven for this kind of operations I added maven after your steps. I created HelloWorld.java just copying from your question. Then I follow these steps:
javac HelloWorld.java
which outputsHelloWorld.class
Then I createdjacoco.exec
by executingjava -javaagent:jacocoagent.jar HelloWorld
Then I created a pom.xml file which contents are like this.
After that I created a
target/classes
directory. I copiedjacoco.exec
totarget/
andHelloWorld.class
totarget/classes
.Then I executed
mvn jacoco:report
which generates a report totarget/site/jacoco
. Which contains correct coverage information.I know using maven may not sound good for a simple application. But I don't know any other way to generate reports from jacoco.exec. By the way your maven plugin version and jacocoagent version must match.
And here the result I get.