Starting out with JaCoco

1,534 views
Skip to first unread message

gopster

unread,
Oct 18, 2012, 10:44:57 PM10/18/12
to jac...@googlegroups.com
Hello everyone.

I was wondering if there is any handy tutorial out there for a novice such as myself to learn? I am part of the validation group in my company, and we are evaluating code coverage tools out there to give us coverage metrics in our upcoming iterations. Does JaCoco work in the same way as the previous emma? With emma 2.1, I was able to instrument and generate reports via the command line. Can JaCoco be executed in the same way?

Thanks!

Marc Hoffmann

unread,
Oct 19, 2012, 1:59:14 AM10/19/12
to jac...@googlegroups.com
Hi,

we don't provide a tutorial but documentation with examples:

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

> Does JaCoco work in the same way as the previous emma?

JaCoCo is way simpler as it does not require to pre-instrument your
code. You simply add the JaCoCo agent as an JVM parameter to collect
execution data.

> With emma 2.1, I was able to instrument and generate reports via the
> command line. Can JaCoco be executed in the same way?

As said, instrumentation is not required any more. For report
generation we provide Ant tasks and a Maven plug-in.

Best regards,
-marc
> --

gopster

unread,
Oct 25, 2012, 5:03:35 PM10/25/12
to jac...@googlegroups.com
Thank you the reply Marc.
 
So I got back into Jacoco this week and stumbled across some more roadblocks which I am sure are simple issues but are puzzling for a novice such as myself.
 
We are running Websphere 8, and I configured the JVM parameter as follows:
 
-javaagent:/export/home/nssadmd/JaCoCo/lib/jacocoagent.jar
 
I ran my tests (not unit tests but rather sending messages via a queue system). I stopped the JVM, and the .exec file was dumped as it should be. I understand we have to use Apache ant to create the report. So I created an ant report task:
 
<jacoco:report>                             
 <executiondata>        
  <file file="jacoco.exec"/>    
 </executiondata>                             
 <structure name="Jacoco">        
  <classfiles>            
   <fileset dir="customerjar"/>
  </classfiles>          
 </structure>  
 
 <html destdir="report"/>                        
</jacoco:report>
 
Where customerjar is the folder containg the jars that contain the core code. The report does get generated, but the coverage remains at 0%. I do see red bars for the different packages in those jars. Am I missing anything in my steps?  
 
 
Thanks again!

Marc R. Hoffmann

unread,
Oct 26, 2012, 9:15:24 AM10/26/12
to jac...@googlegroups.com
Hi,

the coverage report has a link "Sessions" on the top right corner. On
this page, do you find all classes where execution data has been
collected for. Do you see you classes?

Best regards,
-marc
> --
>
>

gopster

unread,
Oct 29, 2012, 6:41:54 PM10/29/12
to jac...@googlegroups.com
Hi Marc:

I am able to open the Sessions file. However, I am guessing "C" Gui icon denotes the classname in the main parent element in Index.html? I am not able to find those classes under the sessions link. Attached is a snippet of what I'm seeing in the Index.html file


Thanks!
Jacoco.bmp

Marc R. Hoffmann

unread,
Oct 30, 2012, 2:39:45 AM10/30/12
to jac...@googlegroups.com
Hi,

if you're classes are not listed on the sessions page this means the
JaCoCo agent has not collected execution data for them. There are two
main reasons:

1) Includes/Excludes: If you configure includes or excludes this might
filter your classes if the given patterns are wrong.

2) Wrong JVM: Especially in APP server context it is sometimes hard to
understand what JVM actually executes your code. If the Agent is
configured for the wrong JVM (e.g. only the launcher tool, which spawns
another JVM) you will only see classes of this tool. Looking at your
sessions page should give you some ideas what you're actually sampling.

Best regards,
-marc
> --
>
>

chinmay...@gmail.com

unread,
Aug 31, 2013, 11:56:26 PM8/31/13
to jac...@googlegroups.com

Hi,

I used Sonar-Jacoco tool for Java code coverage. During the code coverage exercise the JVM was improperly shut down because of power failure.

The Jacoco.out file created but 0 kb size.

Is there any way I can still retrieve the coverage part. Does Jacoco creates any temp file before it writes to Jacoco.out file after the JVM is property shut down.

Thanks,
Chinmay

My setup is correct

Marc R. Hoffmann

unread,
Sep 1, 2013, 4:04:46 AM9/1/13
to jac...@googlegroups.com
No, the *.exec file is the only persisted artifact.

-marc

sapz...@gmail.com

unread,
Jun 1, 2015, 10:46:20 AM6/1/15
to jac...@googlegroups.com
Hello gopster,

I'm too a newbie to Jacoco ! Would like to know how you integrated jacoco agent with websphere , we use websphere build and deploy tool .

Thanks !
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages