question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get Jacoco coverage to work with app in container

See original GitHub issue

This isn’t a bug, but a question. Please remove if this isn’t the place.

Background I am running a Dropwizard app (using java -jar myjar.jar server config.yml) inside a docker container via this plugin, and I’m running integration tests inside it. In my integration test, I know for sure that code is being exercised, but Jacoco coverage reports for the integration tests aren’t showing coverage.

My Questions How do I know that Jacoco is properly attached to the code running inside the container? Do I have to do anything special to extract the coverage report from the running container? I would think that a simple shared volume would work, as I am using now, but that does not seem to be the case. I have a hunch that I need to add the jacoco agent parameters to the java -jar that’s taking place inside my container, but I’m not sure.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
whocommented, Feb 17, 2017

@rhuss

Thanks for the tip - that worked splendidly!

Here’s what I ended up doing:

  1. Configured my integration tests so that they only execute when invoking -P integration-tests
  2. Added a step to the pre-integration-test phase that copies the jacoco runtime jar into a volume that’s shared with the docker container
  3. Altered my dropwizard startup command to include the following:
-javaagent:./target/dependency/org.jacoco.agent-0.7.9-runtime.jar=destfile=./target/coverage-reports/jacoco-it.exec,append=true
  1. Configured my jacoco report to consume jacoco-it.exec over a shared volume.

Thanks again!

To anyone who comes across this issue via Googling for answers: If you are running your Dropwizard integration tests inside a Docker container, you will need to alter your java jar run command to include a properly-configured -javaagent parameter (see http://www.eclemma.org/jacoco/trunk/doc/agent.html). After you do this, you will be able to use a jacoco report step to load the .exec file and convert it to HTML output.

2reactions
whocommented, Feb 17, 2017

One more note for pilgrims coming from search engines:

Sometimes, files created inside a shared volume end up being owned by root on the host box. If you run into this, then I recommend doing the following:

  1. Change the javagent parameter in your jar execution so that it opens a port inside the container for purposes of using jacoco:dump. Here’s mine, for example:
-javaagent:./target/dependency/org.jacoco.agent-0.7.9-runtime.jar=append=true,output=tcpserver,address=*
  1. Add a port mapping for your app, exposing port 6300 to the host:
<port>${docker.app.jacoco}:6300</port>
  1. Before your jacoco integration tests report step, execute a jacoco dump:
<execution>
    <id>post-integration-test-dump</id>
    <phase>post-integration-test</phase>
    <goals>
        <goal>dump</goal>
    </goals>
    <configuration>
        <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
        <port>${docker.app.jacoco}</port>
        <dump>true</dump>
    </configuration>
</execution>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Integration Test code coverage with Java + Docker - Medium
Code coverage is normally associated with unit tests, and tools like jacoco-maven-plugin make it easy. But, if you're testing a backend/API ...
Read more >
Unable to get jacoco coverage - Stack Overflow
I am new to Gradle builds and started implementing CI using Gitlab runner. The jobs work fine and generate the jacoco report as...
Read more >
How to setup a jacoco agent on a Docker Container
Hi , we have our docker container.. i need to execute some tests against this docker container and get a coverage report.
Read more >
Test coverage for containerized java apps - akquinet AG
Setup · Make the JaCoCo agent available inside the container. · Start the app with the JaCoCo agent. · Access the coverage report....
Read more >
How To Generate Code Coverage Report Using JaCoCo ...
To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found