Skip to content

Support GitLab-compatible Cobertura format in MTP natively #190

Open

Description

Hello 👋,

I’m currently using GitLab, which supports displaying code coverage information directly inside the diff view of a merge request. It relies on the Cobertura format for this feature.

Previously, when I was using coverlet, this worked perfectly out of the box. However, after switching to Microsoft.Testing.Platform and the Microsoft.Testing.Extensions.CodeCoverage package, the coverage report stopped working in GitLab.

After some experimentation, I was able to make it work again by manually tweaking the generated Cobertura XML file:

dotnet run -c Release -- --report-junit --coverage --coverage-output-format cobertura --coverage-output myapp.cobertura.xml
sed -i "s@filename=\"$CI_PROJECT_DIR/@filename=\"@g" bin/Release/net9.0/TestResults/myapp.cobertura.xml
sed -i "s@<packages>@<sources><source>$CI_PROJECT_DIR/</source></sources><packages>@g" bin/Release/net9.0/TestResults/myapp.cobertura.xml

The idea here is:

  • Replace all absolute paths in the nodes with relative paths.
  • Add a node containing the base path.

This makes GitLab correctly display coverage information in merge requests.
However, having to run these sed commands after each test run is not ideal.

👉 Question:
Is there already a built-in option or configuration to achieve this behavior natively?
And if not, would it be possible to add support for relative paths and sources in the Cobertura output?

Thanks a lot for your work on this project!

Activity

  1. changed the title [-]MTP cobertura format not compatible with gitlab by default[/-] [+]Support GitLab-compatible Cobertura format in MTP natively[/+] on Oct 8, 2025
  2. fhnaseer commented on Oct 9, 2025

    @fhnaseer
    Member

    You can try using "DeterministicReport" in the coverage settings file. More details in here https://github.com/microsoft/codecoverage/blob/main/docs/configuration.md

  3. latop2604 commented on Oct 9, 2025

    @latop2604
    Author

    Thx, but I don't think it will work, as gitlab will not be able to map it anymore to the real file path.

  4. latop2604 commented on Oct 9, 2025

    @latop2604
    Author

    I tested it using a a testconfig.json file. But did not work.

    {
      "codeCoverage": {
        "Configuration": {
          "DeterministicReport": true
        }
      }
    }

    Is it possible to override /_/ by something I can input somewhere?

  5. fhnaseer commented on Oct 10, 2025

    @fhnaseer
    Member

    No, it is not possible to override this.

  6. latop2604 commented on May 26, 2026

    @latop2604
    Author

    FYI, coverlet now support MTP. So switched back to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions