DEV Community

Mickey Streicher
Mickey Streicher

Posted on • Edited on

Enhancing Merge Requests with Vedro and GitLab Test Reports

As more development teams adopt Continuous Integration (CI) practices, the ability to visualize and manage test results within merge requests becomes increasingly important. GitLab CI provides developers with a user-friendly platform to view test reports directly in the context of their changes, streamlining the workflow and speeding up the review process.

When configured correctly, your GitLab merge request will display a new section illustrating the test report, showcasing which tests passed or failed. This section makes it incredibly easy for reviewers to assess the impact of code changes on the existing codebase, all without leaving the merge request view. The integration appears as follows:

overview

Full Report:

fullreport

Setting Up GitLab CI Test Reports

Step 1: Installing vedro-xunit-reporter

Before generating test reports, you need to install the vedro-xunit-reporter plugin. This plugin will produce test reports in the xUnit XML format, which GitLab CI can interpret and display within merge requests.

To install the plugin, run the following command:

$ vedro plugin install vedro-xunit-reporter
Enter fullscreen mode Exit fullscreen mode

After installing the plugin, remember to add it to your requirements.txt file, ensuring its installation during CI pipeline executions.

Step 2: Configuring .gitlab-ci.yml

The next step involves updating your .gitlab-ci.yml file to define how artifacts and test reports are handled within your GitLab CI pipeline. You will need to specify that the artifact produced by the test stage is a report in the xUnit XML format, and indicate the path where this report can be found.

Here is an example configuration for your .gitlab-ci.yml file:

test:
  image: python:3.11
  stage: test

  before_script:
    - pip install -r requirements.txt

  script:
    - vedro run -r rich xunit --xunit-report-path xunit_report.xml

  artifacts:
    when: always
    reports:
      junit: xunit_report.xml
Enter fullscreen mode Exit fullscreen mode

In the example above, the CI pipeline includes a test stage, running Vedro with the rich and xunit reporters. The --xunit-report-path option specifies the output filename for the test report, which, in this case, is xunit_report.xml.

Additionally, the artifacts:reports:junit section instructs GitLab CI to treat the generated xunit_report.xml file as a JUnit format test report. when: always ensures that the report is saved as an artifact regardless of whether the test passes or fails.

By following these two steps, you can initiate Vedro tests within your GitLab CI pipeline and visually represent the results in merge requests. This integration enhances the efficiency of code reviews by providing immediate and clear feedback on the success of tests related to the proposed code changes. It also helps to catch issues early, prior to merging your code, thus maintaining the stability and reliability of your code base.

Top comments (1)

Collapse
 
robinamirbahar profile image
Robina

Good Job