# How to Set up Test Coverage Profiling for Java
In order to record test coverage for Java, we recommend you use either JaCoCo or the Teamscale JaCoCo Agent, depending on your requirements. If you're using Docker, please check our guide on setting up test coverage recording for Java with Docker.
Which Profiler Should I Use?
Here are a few key questions to guide your decision:
- If you want to profile your unit tests or other automated tests that are run in your CI environment, use JaCoCo.
- If you want to profile manual tests, use the Teamscale JaCoCo Agent.
- If you want to profile a long-running process and want to upload test coverage to Teamscale in regular intervals (e.g., when profiling a web application), use the Teamscale JaCoCo Agent.
In order to set up JaCoCo for automated tests running in your CI environment, install and configure one of its build system plugins:
These plugins will write XML files containing the coverage information to disk after your tests have finished. Refer to the instructions for uploading external analysis results to Teamscale.
# Teamscale JaCoCo Agent
The Teamscale JaCoCo Agent will record coverage for one JVM process and upload the recorded coverage to Teamscale in regular intervals.
To configure the agent for your Java or Kotlin application, go to the Projects perspective and click on the button.
On the next screen, select
Set Up Coverage Profiler.
You will be presented with a dialog that lets you configure the agent:
- Please select the user whose credentials should be used for the coverage upload.
- Please select a partition, which is a logical name that groups related coverage, e.g., the type of test that will be profiled (Manual Test vs. Unit Test vs. Regression Test etc).
- Please select all packages that should be profiled. Subpackages are included as well.
Selecting Appropriate Packages
Teamscale automatically suggests packages to profile to you. Please review them carefully.
Please make sure the packages you select are "future-proof", i.e. if you add further packages in the future, they are included as well. This will save you time later because you won't have to adjust the profiler configuration whenever you add new packages.
Finally, please click
Download Profiler Configuration.
For instructions on how to use this configuration file with the Teamscale JaCoCo Agent, please refer to the agent's documentation
# Uploading Coverage via REST API
Please refer to the article on external uploads for details as to how to upload the resulting coverage to Teamscale.