Reporting on large amounts of JUnit tests in GitLab CI

Posted by Joep Weijers on July 2, 2025

JUnit test results in GitLab CI's pipeline view

We have migrated the Continuous Integration build of our Java monolith from Jenkins to GitLab CI. To report the JUnit test results, we leverage GitLab CI’s artifact report. However, it had some difficulties to cope with our almost 50.000 tests spread across thousands of test classes. Here is how we made it work.

Our Maven build uses JUnit jupiter and the Surefire and Failsafe plugins to generate thousands of TEST-TestClassName.xml files containing test results.

While there are some known issues with large report files, we run into different issues, presumably due to the large amount of test result files. The problem: there are 0 tests reported in the GitLab interface.

Smaller test result files

Example of a JUnit test results XML file, showing a long list of property elements and a few testcase elements

Upon inspection of the test result files, we see that each file contains a long list of all the System properties that were set when the test was running. While this could be useful info to have when debugging tests, we are not interested in this info when the tests pass. This also produces a lot of overhead when sending the test result files to GitLab for parsing as a report. Unfortunately, we can’t configure the surefire plugin and JUnit Jupiter to not include all these properties in the test result files. So this doesn’t solve our problems.

Open Test Reporting

JUnit Jupiter actually calls its default test result files a “legacy” format. It also supports the Open Test Reporting format, which is an event based report in a single file. In the JUnit 5 manual you can find how to use the Open Test Reporting format. Note that with the setup JUnit will generate both the legacy reports and the open-test-report.xml file. We can configure the GitLab CI to only use the open-test-report.xml file for the JUnit artifact report. Unfortunately, GitLab does not support the Open Test Reporting format (yet). So this doesn’t solve our problems.

Reports per module

Going of our hunch that the large amount of files is the issue, we looked into ways to provide GitLab with the test results in smaller batches. One attempt is to have a job for each Maven module in the root folder of our monolith, that pushes all test result files under that module.

GitLab pipeline view showing 82 jobs

This gives us around 80 concurrent jobs that each generate a bit of the final report. And this approach works, now the test results do become available in the GitLab interface.

Gitlab showing test results, grouped per module

However, this solution is error prone, because we need to remember to also update this list whenever adding a module in the root folder of the project. Also running 80 concurrent jobs that all have to copy over the artifacts from the Maven build is quite a big load on our infrastructure and they take several minutes to execute.

Custom script to aggregate test results

The JUnit XML test result format also supports reporting multiple testsuites in a single file. So we can post-process our individual test result files to combine them into one file. This post-processing step also allows us to filter out the large, duplicate blocks of properties. The following bash script uses xmlstarlet to achieve this:

#!/bin/bash

# Check for xmlstarlet
if ! command -v xmlstarlet &> /dev/null
then
    echo "xmlstarlet could not be found, please install it to proceed."
    exit
fi

# Output file
output_file="target/test-results.xml"
mkdir -p target

# Start the combined output with a <testsuites> element
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "$output_file"
echo "<testsuites>" >> "$output_file"

# Loop through each TEST-*.xml file
find . -type f -name 'TEST-*.xml' | while read -r file; do
    # Extract the <testsuite> element, excluding <properties>, and append to output file
    xmlstarlet ed -d "/testsuite/properties" "$file" | xmlstarlet sel -t -c "/testsuite" >> "$output_file"
done

# Close the <testsuites> element
echo "</testsuites>" >> "$output_file"

echo "Combined JUnit XML files into $output_file"

The post-processing takes around 30 seconds to complete and gives us a 10MB xml file containing all test results. GitLab can handle this single file and now shows the test results properly:

JUnit test results shown in GitLab's pipeline view

Joep Weijers

Joep is a Developer Experience Engineer at TOPdesk with a keen interest in delivering quality software continuously. He loves playing around with GitLab CI pipelines, Selenium, Docker, Kubernetes and keeps in touch with his inner developer by educating his colleagues on testable Java code.

More Posts - Website