Search code examples
gitlabjunit5

In Gitlab CI/CD how do I get the Tests tab to correctly show junit5 tests output


I'm trying to fully integrate our JUnit Suites into gitlab and struggling with the output on the "tests" tab. image of the test results

What I have is a results summary given the .gitlab-ci.yml step, what I'd like is a breakdown of each tests name/time to complete/status.

When I look inside the TEST*Name_of_Test.xml I can see the individual tests with their time breakdowns: individual tests

Here's what my stage looks like in the gitlab-ci.yml config: gitlab-ci.yml stage configuration

Anyone have suggestions as to how I could properly configure the gitlab-ci.yml stage to get the broken-out unit tests run?


Solution

  • While not a perfect solution. This is a work around, see image result: enter image description here

    Here's what I had to do:

    It looks like this: fixJunitReports.sh

    #!/bin/bash
    
    totalTime=0;
    totalTests=0;
    totalErrors=0;
    totalSkipped=0;
    totalFailures=0;
    for testResult in $1/target/surefire-reports/*TEST*.xml ; do
       tsName=$(grep -Pio '<testsuite.*name="\K[^"]*' $testResult)
       tsTime=$(grep -Pio '<testsuite.*time="\K[^"]*' $testResult)
       totalTime=$(echo "$totalTime $tsTime" | awk '{print $1 + $2}');
       tsTests=$(grep -Pio '<testsuite.*tests="\K[^"]*' $testResult)
       totalTests=$((totalTests+tsTests));
       tsErrors=$(grep -Pio '<testsuite.*errors="\K[^"]*' $testResult)
       totalErrors=$((totalErrors+tsErrors));
       tsSkipped=$(grep -Pio '<testsuite.*skipped="\K[^"]*' $testResult)
       totalSkipped=$((totalSkipped+tsSkipped));
       tsFailures=$(grep -Pio '<testsuite.*failures="\K[^"]*' $testResult)
       totalFailures=$((totalFailures+tsFailures));
    done
    
    # Now build master file.
    rm -f $1/target/surefire-reports/junit_report.xml
    echo '<?xml version="1.0" encoding="UTF-8" ?>' >> $1/target/surefire-reports/junit_report.xml
    echo '<testsuites id="junit_run" name="'$tsName'" tests="'$totalTests'" failures="'$totalFailures'" time="'$totalTime'">' >> $1/target/surefire-reports/junit_report.xml
    tail --lines=+2 $1/target/surefire-reports/*TEST*.xml >> $1/target/surefire-reports/junit_report.xml
    echo '</testsuites>' >> $1/target/surefire-reports/junit_report.xml
    
    • Then I added it into the image that we use for builds: Dockerfile

    • Finally I modified our stage slightly: modified stage