Search code examples
gitlabgitlab-ci

Multiple coverage reports and badges for GitLab Tests


In our mono repo, hosted on a GitLab server, we have multiple types of tests, e.g., for

  1. C,
  2. Pyhton, and,
  3. Java,

that run in a CI/CD pipeline setup (GitLab is version v16.8.1).

For all these tests a Cobertura coverage XML report is created. The .gitlab-ci.yml looks something like this:

test_c:
  stage: test
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  script:
    - ./test_script_c.sh
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: build/tests/c/CoberturaCoverageScripts.xml

test_python:
  stage: test
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  script:
    - ./test_script_python.sh
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: build/tests/python/CoberturaCoverageScripts.xml

test_java:
  stage: test
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  script:
    - ./test_script_java.sh
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: build/tests/java/CoberturaCoverageScripts.xml

This has now the downside, that

  1. only one coverage number is reported on the landing page of the repostiory,
  2. only one coverage number is reported on the MR, and
  3. only one coverage badge is created on the landing page of the repostiory,

Especially on the MRs, this is quite bad. As I only know that the overall project test coverage is like that, but I would need to know that the most important coverage (e.g., C) has not gotten worse and is not catched by an improved test coverage in the e.g., Java part of the project.

GitLab CI Test Coverage

Is there an option to have all three coverage reports shown on at least the MR, i.e., find a setup for the GitLab CI/CD pipeline that shows multiple test coverage numbers.


Solution

  • This is only a partial answer, but you can see the coverage results of different jobs when pointing the mouse on the ? next to the coverage value in your MR. Here is an example screenshot from one of my projects:

    enter image description here

    Still I would be also happy to see a solution on how I can create separate badges for each job.