How to start with Jacoco API

723 views
Skip to first unread message

Ondrej Zoricak

unread,
Apr 3, 2017, 1:25:30 PM4/3/17
to JaCoCo and EclEmma Users
Hello guys.

I read documentations and I find some examples but I didn't find any example how to write code coverage program using Jacoco API. I need just number of lines which are executed when some external program is running so I expected that my program should build and run this external project and give me some result... but do I need Jacoco plugin for this or how is it working? Thank you for any help.

Marc Hoffmann

unread,
Apr 5, 2017, 4:50:24 AM4/5/17
to jac...@googlegroups.com

Hallo Ondrej,

there is a couple of out-of-the-box solutions to do this:

  1. Launch your program within Eclipse in coverage mode (using the EclEmma code coverage plug-in http://www.eclemma.org/)
  2. Launch your program with a Maven build (using JaCoCo maven plugin http://www.jacoco.org/jacoco/trunk/doc/maven.html)
  3. Launch your program with a Ant build (using the JaCoCo Ant tasks http://www.jacoco.org/jacoco/trunk/doc/ant.html)
  4. Use any other integration of JaCoCo (http://www.jacoco.org/jacoco/trunk/doc/integrations.html)

Regards,
-marc

 

 

On 2017-04-03 19:25, Ondrej Zoricak wrote:

Hello guys.
 
I read documentations and I find some examples but I didn't find any example how to write code coverage program using Jacoco API. I need just number of lines which are executed when some external program is running so I expected that my program should build and run this external project and give me some result... but do I need Jacoco plugin for this or how is it working? Thank you for any help.

 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/8707283c-4baa-4748-9669-f8b5a5968eb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Ondrej Zoricak

unread,
Apr 5, 2017, 7:20:14 AM4/5/17
to JaCoCo and EclEmma Users
These solutions will provide code coverage for my program but I want to create program which will create code coverage for external programs... Like I will run my program then will set project directory of some external program and my program will show code coverage information... so user will have result with zero effort and dependency on IDE... So I want to know if is there some way to use Jacoco API provide these features and if yes what is prerequisite do so.

Thank you again.

Marc Hoffmann

unread,
Apr 5, 2017, 8:34:07 AM4/5/17
to jac...@googlegroups.com

Hi,

well, if you want to write everything yourself, here are the steps:

  1. Launch your external program with the JaCoCo agent (http://www.jacoco.org/jacoco/trunk/doc/agent.html)
  2. After program terminates create a report (example http://www.jacoco.org/jacoco/trunk/doc/examples/java/ReportGenerator.java). For this you need the *.exec file created by the agent, the class files of your application (JARs will also do the job) and the Java source files if you want syntax highlighting.

Regards,
-marc

Ondrej Zoricak

unread,
Apr 6, 2017, 6:12:28 AM4/6/17
to JaCoCo and EclEmma Users
Thank you for your suggestion. Because I am new with Jacoco and Javaagent I needed couple of hours to find out how Javaagent works and how it is working with Jacocoagent(and what is this Jacocoagent). I made research and I think I have two options:

1. I find out that it is little bit difficult to provide solutions for external projects because I will need Javaagent connected to some server(glassfish, tomcat) and run javaagent with jacocoagent and with pertaining project and then It will generate *.exec file and I will need use Jacoco API to parse data... Am I right? 

2. So I think it will be easier find out which kind(maven, and, gradle) of external project is it. Then modify build and add Jacoco plugin and generate *.exec file and then just parse this file with Jacoco API... Am I right?

Please give me some clue which one solution is better(so will easier to implement, will go to a less troubles and will cover wide scale of programs). 

Thank you again Marc.

Marc Hoffmann

unread,
Apr 6, 2017, 8:06:57 AM4/6/17
to jac...@googlegroups.com

Hi,

if you're new with this I definitely recommend not to write your own integration with JaCoCo. There are out-of-the-box integrations for Maven, Ant and Gradle. Also for report generation. There is no need to use the JaCoCo API at all. There are thousands of projects out there which use these standard tools.

Regards,
-marc

Reply all
Reply to author
Forward
0 new messages