JaCoCo code coverage metrics from remote tests

1,726 views
Skip to first unread message

majdh...@gmail.com

unread,
Jan 12, 2018, 6:57:36 AM1/12/18
to JaCoCo and EclEmma Users
Hello everyone :)

We currently have Sonar + JaCoCo Maven Plugin (0.7.9) installed to get code coverage metrics on our services. Our Unit tests all run on the Jenkins server and this is where the code coverage report is produced and analysed. After the services are built on the Jenkins server, they are then deployed on a test dedicated server.

End to End tests that are executed by other teams run on the aforementioned test server. These tests end up hitting our services. 

Using JaCoCo, would it be possible to get code coverage stats from these E2E tests that use our services?

I have read the following guides related to the JaCoCo remote agent;

If I understood correctly, the remote agent will need to be loaded in the JVM (on our test server in this case) and the services executing the tests (run by other teams) will need to have JaCoCo plugin settings included in the POM file. Is this assumption correct?

I hope my explanation was clear. I hope someone can help me patch the gaps in my knowledge there!

Thanks
Majd

Evgeny Mandrikov

unread,
Jan 15, 2018, 8:15:13 AM1/15/18
to JaCoCo and EclEmma Users

On Friday, January 12, 2018 at 12:57:36 PM UTC+1, majdh...@gmail.com wrote:
I hope someone can help me patch the gaps in my knowledge there!


Yes - you can remotely get execution data from JaCoCo agent attached to JVM under test.

Agent as described at http://www.jacoco.org/jacoco/trunk/doc/agent.html has option "output":
  • file: At VM termination execution data is written to the file specified in the destfile attribute.
  • tcpserver: The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • tcpclient: At startup the agent connects to the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
and option "jmx":
  • If set to true the agent exposes functionality via JMX
Agent can be configured with help of Ant Tasks or Maven Plugin or even without them.

Exposed via JMX functionality as described in JavaDoc ( http://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/IAgent.html ) among others provides three following methods:
  • byte[] getExecutionData(boolean reset) Returns current execution data.
  • void dump(boolean reset) Triggers a dump of the current execution data through the configured output.
  • void reset() Resets all coverage information.
Again from documentation there is also Ant Task "dump" - http://www.jacoco.org/jacoco/trunk/doc/ant.html:
This task allows to remotely collect execution data from another JVM without stopping it. Remote dumps are useful for long running Java processes like application servers.

"dump" command in Command Line Interface - http://www.jacoco.org/jacoco/trunk/doc/cli.html
"dump" goal in jacoco-maven-plugin - http://www.jacoco.org/jacoco/trunk/doc/dump-mojo.html

API usage examples ( http://www.jacoco.org/jacoco/trunk/doc/api.html ) include:
  • MBeanClient.java This example connects to a coverage agent to collect execution data over the JMX.
  • ExecutionDataClient.java This example connects to a coverage agent to collect execution data over the remote protocol.
  • ExecutionDataServer.java This example starts a socket server to collect execution data from agents over the remote protocol.
Please note that generation of report in addition to execution data requires exactly the same class files as in JVM under tests.

The way how you and your teams will use all this is entirely up to you.

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