Java, JavaFX, code coverage and GitLab CI

Kai Winter
Feb 16, 2016 · 2 min read

One drawback of GitLab compared to GitHub are the missing third party services like Travis CI or Coveralls. On GitLab we have GitLab CI. On first sight it is very powerful as you can define a docker container in which your application gets deployed and tested.

For Java the documentation isn’t very verbose at the moment, it is hard to find good examples. This article may be one.
To test a Java application you can use one of the official java images. Unless your code depends on JavaFX which is not contained in the OpenJDK which is used in those images.

Own docker image to the rescue

What’s necessary here is a docker container with

  • Oracle JDK 1.8 (including JavaFX)
  • Maven (to run the build)

I found a good starting point in an existing docker image which I used as a reference and stripped down to the things listed above. You’ll find it later in this text.

Configure code coverage reporting

GitLab CI can report the code coverage of your unit tests in the build results of the web UI. You have to configure this in your project’s settings in the Continuous Integration section. But first…

Add jacoco to your pom.xml
To collect coverage information for your tests add this to your pom file.


Set-up your project
Go to your Project Settings and find the Continuous Integration section. Use this string for Test coverage parsing:


This regex is used after the build to parse the jacoco coverage result in percent from the console. We make sure that the coverage result is printed to the console in our .gitlab-ci.yml file.


This is the complete .gitlab-ci.yml file. Pretty short.

  • The image kaiwinter/docker-java8-maven contains JavaFX and a maven installation
  • “mvn install -B” builds and tests your application
  • “cat target/site/jacoco/index.html” prints the result of the coverage to the console
image: kaiwinter/docker-java8-mavenjob1:
-"mvn install -B"
-"cat target/site/jacoco/index.html"

That’s it

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store