GitLab may not work properly because you are using an outdated web browser.
Please install a supported web browser for a better experience.

JUnit test reports

Introduced in GitLab 11.2. Requires GitLab Runner 11.2 and above.

Overview

It is very common that a CI/CD pipeline contains a test job that will verify your code. If the tests fail, the pipeline fails and users get notified. The person that works on the merge request will have to check the job logs and see where the tests failed so that they can fix them.

You can configure your job to use JUnit test reports, and GitLab will display a report on the merge request so that it's easier and faster to identify the failure without having to check the entire log.

Use cases

Consider the following workflow:

  1. Your master branch is rock solid, your project is using GitLab CI/CD and your pipelines indicate that there isn't anything broken.
  2. Someone from you team submits a merge request, a test fails and the pipeline gets the known red icon. To investigate more, you have to go through the job logs to figure out the cause of the failed test, which usually contain thousands of lines.
  3. You configure the JUnit test reports and immediately GitLab collects and exposes them in the merge request. No more searching in the job logs.
  4. Your development and debugging workflow becomes easier, faster and efficient.

How it works

First, GitLab Runner uploads all JUnit XML files as artifacts to GitLab. Then, when you visit a merge request, GitLab starts comparing the head and base branch's JUnit test reports, where:

  • The base branch is the target branch (usually master).
  • The head branch is the source branch (the latest pipeline in each merge request).

The reports panel has a summary showing how many tests failed and how many were fixed. If no comparison can be done because data for the base branch is not available, the panel will just show the list of failed tests for head.

There are three types of results:

  1. Newly failed tests: Test cases which passed on base branch and failed on head branch
  2. Existing failures: Test cases which failed on base branch and failed on head branch
  3. Resolved failures: Test cases which failed on base branch and passed on head branch

Each entry in the panel will show the test name and its type from the list above. Clicking on the test name will open a modal window with details of its execution time and the error output.

Test Reports Widget

How to set it up

NOTE: Note: For a list of supported languages on JUnit tests, check the Wikipedia article.

To enable the JUnit reports in merge requests, you need to add artifacts:reports:junit in .gitlab-ci.yml, and specify the path(s) of the generated test reports.

In the following examples, the job in the test stage runs and GitLab collects the JUnit test report from each job. After each job is executed, the XML reports are stored in GitLab as artifacts and their results are shown in the merge request widget.

NOTE: Note: If you also want the ability to browse JUnit output files, include the artifacts:paths keyword. An example of this is shown in the Ruby example below.

Ruby example

Use the following job in .gitlab-ci.yml. This includes the artifacts:paths keyword to provide a link to the JUnit output file.

## Use https://github.com/sj26/rspec_junit_formatter to generate a JUnit report with rspec
ruby:
  stage: test
  script:
  - bundle install
  - rspec spec/lib/ --format RspecJunitFormatter --out rspec.xml
  artifacts:
    paths:
      - rspec.xml
    reports:
      junit: rspec.xml

Go example

Use the following job in .gitlab-ci.yml:

## Use https://github.com/jstemmer/go-junit-report to generate a JUnit report with go
golang:
  stage: test
  script:
  - go get -u github.com/jstemmer/go-junit-report
  - go test -v 2>&1 | go-junit-report > report.xml
  artifacts:
    reports:
      junit: report.xml

Java examples

There are a few tools that can produce JUnit reports in Java.

Gradle

In the following example, gradle is used to generate the test reports. If there are multiple test tasks defined, gradle will generate multiple directories under build/test-results/. In that case, you can leverage glob matching by defining the following path: build/test-results/test/**/TEST-*.xml:

java:
  stage: test
  script:
  - gradle test
  artifacts:
    reports:
      junit: build/test-results/test/**/TEST-*.xml

Maven

For parsing Surefire and Failsafe test reports, use the following job in .gitlab-ci.yml:

java:
  stage: test
  script:
  - mvn verify
  artifacts:
    reports:
      junit:
        - target/surefire-reports/TEST-*.xml
        - target/failsafe-reports/TEST-*.xml

C/C++ example

There are a few tools that can produce JUnit reports in C/C++.

GoogleTest

In the following example, gtest is used to generate the test reports. If there are multiple gtest executables created for different architectures (x86, x64 or arm), you will be required to run each test providing a unique filename. The results will then be aggregated together.

cpp:
  stage: test
  script:
  - gtest.exe --gtest_output="xml:report.xml"
  artifacts:
    reports:
      junit: report.xml

Limitations

Currently, the following tools might not work because their XML formats are unsupported in GitLab.

Case Tool Issue
<testcase> does not have classname attribute ESlint, sass-lint https://gitlab.com/gitlab-org/gitlab-foss/issues/50964
线上太阳城信誉网址-真人太阳城开户注册-现金太阳城娱乐平台 线上永利直营注册 现金威尼斯人 直营网址 真人新濠天地开户 现金美高梅网址直营 现金威尼斯人注册 真人平台娱乐 现金葡京开户网址 线上直营 现金平台注册 太阳城平台注册 注册开户 真人直营 真人网址平台
网址平台 真人平台网址 开户直营 现金太阳城直营开户 现金网址平台 真人太阳城娱乐开户 太阳城网址平台 线上网址 平台开户 太阳城注册直营 真人开户注册 现金太阳城平台注册 现金注册网址 真人注册娱乐 真人太阳城娱乐直营 真人太阳城娱乐网址 太阳城注册娱乐 线上注册 现金太阳城直营平台 现金太阳城注册直营 真人太阳城 现金太阳城平台直营 真人太阳城平台注册 现金网址平台 现金开户娱乐 真人娱乐平台 线上开户娱乐 线上太阳城直营娱乐 真人太阳城平台注册 线上太阳城平台开户 真人太阳城平台注册 真人平台娱乐 太阳城开户平台 线上太阳城网址开户 线上网址 真人直营 真人太阳城网址开户 线上开户注册 线上注册开户 太阳城娱乐注册 太阳城平台网址 线上太阳城平台直营 现金太阳城平台 真人太阳城网址注册 线上注册平台 线上注册平台 线上太阳城平台直营 太阳城平台直营 现金平台 现金太阳城平台注册 开户直营 线上开户娱乐 真人太阳城开户直营 现金太阳城网址娱乐 现金网址 线上太阳城注册网址 现金网址开户 现金太阳城平台注册 直营娱乐 直营开户 真人网址娱乐 真人平台 太阳城平台注册 线上太阳城平台开户 线上平台直营 线上太阳城注册平台 注册开户 线上注册直营 真人开户娱乐 现金太阳城直营 线上太阳城娱乐网址 现金太阳城网址直营 线上注册开户 现金娱乐网址 现金太阳城注册直营 真人太阳城平台开户 现金太阳城开户 现金太阳城开户网址 线上直营开户 现金太阳城直营 现金娱乐直营 太阳城开户直营 开户娱乐 真人太阳城平台直营 线上注册娱乐 真人注册开户 线上太阳城注册开户 平台网址 真人太阳城平台开户 现金太阳城娱乐 线上太阳城直营网址 现金注册平台 现金太阳城注册娱乐 现金娱乐 线上太阳城直营平台 现金太阳城注册开户 真人娱乐 线上太阳城直营开户 太阳城直营 现金太阳城平台 真人太阳城网址平台 真人太阳城注册平台 线上太阳城注册娱乐 线上网址 现金注册直营 真人太阳城直营娱乐 线上太阳城开户娱乐 真人太阳城直营 线上太阳城娱乐网址 线上太阳城平台 真人太阳城开户注册 线上网址娱乐 现金太阳城娱乐开户 线上太阳城注册网址 现金太阳城直营 现金直营网址 线上太阳城平台 太阳城网址注册 现金开户 真人太阳城平台开户 真人注册网址 线上娱乐 真人直营网址 真人太阳城平台 真人太阳城网址 线上太阳城开户直营 线上太阳城娱乐注册 线上太阳城平台娱乐 注册直营 太阳城娱乐直营 直营网址 真人娱乐平台 现金太阳城网址直营 真人网址平台 现金太阳城平台注册 太阳城直营开户 线上太阳城平台网址 真人网址娱乐 线上太阳城开户直营 娱乐开户 真人太阳城直营开户 线上平台注册 线上太阳城网址开户 现金太阳城网址平台 现金太阳城平台娱乐 真人太阳城网址娱乐 真人太阳城开户直营 真人直营开户 太阳城开户平台 线上太阳城开户平台 真人太阳城开户网址 娱乐网址 现金太阳城直营开户 注册直营 线上太阳城娱乐直营 现金太阳城注册平台 现金太阳城注册直营 现金平台娱乐 线上平台开户