Support GitLab-compatible Cobertura format in MTP natively

Open
#190 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
testing-qa

Research direction

Start by running the documented dotnet command with --coverage-output-format cobertura and inspect the generated Cobertura XML. Compare its class filenames and package structure with the relative paths and sources required by GitLab; done means the native output works without the post-processing sed commands and preserves valid coverage data.

Written by the indexing model from the issue text.

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!

Dominant language
C#
Stars
125
Forks
17
Avg merge
1h 17m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/codecoverage

All issues in microsoft/codecoverage

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.