Code coverage visualisation in Merge Requests

Replace this template with your information

Readin https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html it looks like it is possible to make use of code coverage visualisation in merge requests.

Unfortunately, I can’t get any coverage report in my MRs.

My configuration:

image: node:12-alpine

test:
  script:
    - yarn install
    - yarn test:ci
  artifacts:
    reports:
      cobertura: coverage/jest/cobertura-coverage.xml
    expire_in: 1 week
  when: always
  only:
     - merge_requests

In a job report:

Uploading artifacts...
coverage/jest/cobertura-coverage.xml: found 1 matching files and directories 
Uploading artifacts as "cobertura" to coordinator... ok  id=**** responseStatus=201 Created token=****

When coverage is dropping there is no visualisation for it, the same is when coverage increases.

What is wrong here and what can be improved?

Hi @orthodoz - Thanks for posting!

If you can upload a bit of the cobertura-coverage.xml file or provide a link to the project if public I can take a look. I did want to call out there’s a known limitation that the parser does not support the <source> element. It is assumed that the filename of a class element contains the full path relative to the project root.

Hopefully this helps!

-James H, GitLab Product Manager, Verify:Testing

1 Like

Hi James, thanks for your reply!

It is a private project, therefore, unfortunately, I can’t share any details like that.

I can share following from my cobertura-coverage.xml:

  <sources>
    <source>/home/app/project-folder</source>
  </sources>
<packages>
    <package name="src" line-rate="0" branch-rate="1">
      <classes>
        <class name="App.tsx" filename="src/App.tsx" line-rate="0" branch-rate="1">
          <methods>
            <method name="(anonymous_0)" hits="0" signature="()V">
              <lines>
                <line number="5" hits="0"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="5" hits="0" branch="false"/>
            <line number="6" hits="0" branch="false"/>
          </lines>
        </class>

Does it help or I need to provide more info?

Thanks!

That helps @orthodoz - If the git root of your project is “project-folder” the feature should be working as intended. If it is not you’ll need get the path more clearly defined.

-James H, GitLab Product Manager, Verify:Testing

Yes, @jheimbuck_gl, project-folder is a root, in a root folder, I have coverage folder with jest/cobertura-coverage.xml in it.

Still, no luck to obtain any Cobertura results for tests.

@orthodoz - i just want to confirm you are looking at the changes tab on the MR as that is where this information appears? Here’s an example from the GitLab project.

Beyond that i’m stumped but I’ve asked the team to take a look to make sure i’m not missing something.

-James H, GitLab Product Manager, Verify:Testing

@jheimbuck_gl - I am facing a similar issue on a self-hosted GitLab instance (version 13.2.4). I am essentially using the gradle example configuration from the code coverage example documentation. Like @orthodoz I see that the cobertura-coverage.xml file is uploaded and I can download it from the pipeline (although it is cobertura-coverage.xml.gz at that point). In my cobertura-coverage.xml file, the source tag is set to src/main/java and each of the filename attributes on the class elements also starts with src/main/java.

I tried to search through some of the source code and debug a little, but I haven’t really done any work with Vue or Ruby, so progress is a little slow. On the browser side, stepping through some of the JS code, it seems that endpointCoverage is not set and therefore fetchCoverageFiles is never called for me, but I have not been able to trace that back to what condition is missing on the backend.

Here are a few things I have tried without success:

  1. gradle example exactly as shown in the documentation
  2. change the XML file name to match the “default” name shown in the ruby code
  3. upload the XML file as a plain artifact and a report artifact
  4. running in a branch pipeline vs merge (detached) pipeline
  5. both the source and target branches having a coverage report

Below is a snippet from the logs of the job uploading the artifact:

$ python3 /opt/cover2cover.py build/jacoco/jacoco.xml src/main/java > build/cobertura-coverage.xml
$ python3 /opt/source2filename.py build/cobertura-coverage.xml
src/main/java
Uploading artifacts for successful job
Uploading artifacts...
build/cobertura-coverage.xml: found 1 matching files and directories
Uploading artifacts as "cobertura" to coordinator... ok id=5413 responseStatus=201 Created token=******
Job succeeded

Unfortunately, I also cannot provide access to my project as it is proprietary, but I would be happy to provide what additional information I can.

I solved my problem. It turns out the 13.2.4 documentation mentions enabling the :coverage_report_view feature flag, but the newer documentation I was looking at does not. I enabled the feature flag and it started working!