DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Keep Your Application Secrets Secret
  • Zero to Hero on Kubernetes With Devtron
  • Testing Serverless Functions
  • Microservices Testing: Key Strategies and Tools

Trending

  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • Build a Voice Assistant With Gemini Live API
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Code Coverage for JavaFX With GitLab CI

Code Coverage for JavaFX With GitLab CI

Looking to test an application with JavaFX on GitLab CI? Let me show you how it's done...

By 
Kai Winter
·
Jul. 07, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

One drawback of GitLab compared to GitHub is the missing third party services like Travis CI or Coveralls. On GitLab we have GitLab CI. At 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. Hopefully, 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 used in those images.

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 on in this post.

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.

<build>
   <plugins>
      <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
         <version>0.7.5.201505241946</version>
         <executions>
            <execution>
               <id>pre-unit-test</id>
               <goals>
                  <goal>prepare-agent</goal>
               </goals>
            </execution>
            <execution>
               <id>post-unit-test</id>
               <phase>test</phase>
               <goals>
                  <goal>report</goal>
               </goals>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>


Set up your project

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

Total.*?([0-9]{1,3})%


Image title

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.

.gitlab-ci.yml

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-maven

job1:
 script:
 - "mvn install -B"
 - "cat target/site/jacoco/index.html"

That’s It!

Image title


Continuous Integration/Deployment Code coverage GitLab JavaFX unit test Docker (software) application Java (programming language)

Published at DZone with permission of Kai Winter. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Keep Your Application Secrets Secret
  • Zero to Hero on Kubernetes With Devtron
  • Testing Serverless Functions
  • Microservices Testing: Key Strategies and Tools

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook