Skip to main content
In this guide, you’ll learn how to collect JUnit-style XML results from a Node.js project using Mocha, upload them as artifacts in GitLab CI/CD, and visualize test reports in merge requests and pipelines. We’ll cover:
  1. Basic artifacts configuration
  2. Customizing retention and upload settings
  3. Enabling artifacts:reports for JUnit
  4. Available report types
  5. Viewing failures in a merge request
  6. Analyzing test summaries in the pipeline

Prerequisites

Install the JUnit reporter locally:
Ensure your package.json test script invokes the reporter.

1. Basic CI/CD Job to Run Tests and Upload Artifacts

Start with a simple CI job that runs tests and uploads all generated files upon success:
This configuration uploads every file created during the job and retains them for 30 days.

2. Always Upload & Customize Artifact Retention

To ensure test results are available even on failure, adjust the artifacts block:
  • when: always – captures artifacts on success or failure
  • expire_in: 3 days – limits storage time to 3 days
  • name – assigns a meaningful archive name
  • paths – points to the JUnit XML file

Generating the JUnit XML

Make sure your test command includes the JUnit reporter:
A sample test-results.xml:

3. Registering JUnit Reports with artifacts:reports

GitLab can parse JUnit XML and display it natively in merge requests and pipeline views. Extend your job:
This enables the Test Reports tab in merge requests and shows detailed test metrics in the pipeline.

4. Available Artifact Report Types

GitLab supports a variety of built-in report types that surface in Merge Request widgets and the pipeline UI:
The image shows a GitLab documentation page about CI/CD artifact report types, detailing how to use artifacts:reports for collecting various reports in jobs. The page includes a sidebar with navigation links and a list of report types.

5. Viewing Failures in a Merge Request

When tests fail, GitLab surfaces a summary of the failures directly in the Merge Request:
The image shows a GitLab documentation page about viewing failed tests in unit test reports. It includes a test summary panel with details of failed tests and navigation options on the side.

6. Checking Test Summaries in the Pipeline

In the pipeline’s Tests tab, you’ll see:
  • Total tests run
  • Number of failures
  • Success rate (%)
  • Average test duration
The image shows a GitLab documentation page about viewing unit test reports, displaying a summary of test results with 3 tests, 2 failures, and a 33.33% success rate.
After job completion, artifact upload logs appear:
You can browse or download the raw XML:
Or view it visually:
The image shows a GitLab CI/CD pipeline test report with 11 successful tests, each related to fetching planet details, achieving a 100% success rate.

References

Watch Video