Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jacoco + tomcat = jacoco.exec, Reporting zero coverage. Help.

Tags:

tomcat

jacoco

I have a web application deployed on Tomcat. Before I get into further details let me spell out the versions.

Versions: jdk 1.7, Tomcat - 7.0.19, jacoco -0.5.6

I have added jdk1.7 to Tomcat. In \apache-tomcat-7.0.19\bin\startup.bat file I have added.

SET JAVA_HOME=C:\ProgramFiles\Java\jdk1.7.0

Also I have added jacoco agent to Tomcat. In apache-tomcat-7.0.19\bin\catalina.bat I have added.

SET JACOCO=-javaagent:<my download folder>\jacoco-0.5.6.201201232323\lib\jacocoagent.jar=destfile=C:\jacoco.exec,append=true,includes=* 
set JAVA_OPTS=%JAVA_OPTS% %JACOCO%

Now, when I fire up Tomcat, and hit my web applications, as expected there is a C:\jacoco.exec file.

I have now moved the code to the following directory structure jacoco.exec /bin/ /coveragereport

Now I have used the class ReportGenerator from http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java. I have got a bunch of reports in HTML format in the /coveragereport directory. However, all code is being shown as non touched. Although after I have fired up Tomcat I had gone to the http://localhost:/ and browsed around. I was hoping to get a coverage percentage reported.

I am missing something very basic. Help please.

like image 292
davejohn Avatar asked Mar 23 '12 11:03

davejohn


People also ask

Why does JaCoCo not show coverage?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.

How do I get my JaCoCo code coverage report?

Step 4: To get you code coverage report navigate to the target > site > jacoco > index. html > right-click > Open In > Browser > And your preferred browser. So basically index. html is your code coverage report file.

How do I check my JaCoCo coverage?

JaCoCo reports help us visually analyze code coverage by using diamonds with colors for branches, and background colors for lines: Red diamond means that no branches have been exercised during the test phase. Yellow diamond shows that the code is partially covered – some branches have not been exercised.

What is JaCoCo instruction coverage?

The smallest unit JaCoCo counts are single Java byte code instructions. Instruction coverage provides information about the amount of code that has been executed or missed. This metric is completely independent from source formatting and always available, even in absence of debug information in the class files.


1 Answers

Tomcat will write the Jacoco file on shutdown.

like image 156
Manuel Avatar answered Sep 23 '22 13:09

Manuel