Setting up Jacoco using gradle to calculate java code coverage during System Testing

I hope a similar question hasn’t been asked already. If so, please point me to the right location.

I am conducting system tests on a web application using the protractor/selenium framework with the test cases in Jasmine. The server side is written in Java and I need to conduct code coverage (statement and function level) on the java classes to gauge if we are missing out on some behaviours during our BDD system tests.

Our code is being built using gradle and I intend to use JaCoCo to conduct the coverage. As per my understanding, I need to create an instrumented build of my extension, which will have the appropriate hooks set in by JaCoCo. Hence, when I run the system tests using Protractor, JaCoCo will conduct the code coverage.

Can you please provide relevant documentation to go about this? To be clear, I don’t need a direct solution, just the relevant material/guidance to set myself in the right path. Thanks for helping me out in this!

JaCoCo has two methods of operation, on the fly instrumentation via the java agent and offline instrumentation

I suggest you use on-the-fly instrumentation and add the jacoco agent to the jvm args of your application prior to running jasmine/selenium. See here for an example which adds the jacoco agent to the testkit jvm in a gradle build.

If you instead want gradle to invoke offline instrumentation I’d guess you’d want to invoke the jacoco ant task (assuming one exists).

For reference the gradle jacoco plugin uses on-the-fly instrumentation and doesn’t invoke offline instrumentation.

1 Like

Thanks for the response, Lance. I shall look further into using on the fly instrumentation of jacoco. Thanks again!