You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support GitLab-compatible Cobertura format in MTP natively #190
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!
Reacted by matteotrapani, petit-blaireau, Victor Molostov and Mark Preston
changed the title [-]MTP cobertura format not compatible with gitlab by default[/-][+]Support GitLab-compatible Cobertura format in MTP natively[/+]on Oct 8, 2025
Activity
[-]MTP cobertura format not compatible with gitlab by default[/-][+]Support GitLab-compatible Cobertura format in MTP natively[/+]fhnaseer commentedon Oct 9, 2025
You can try using "DeterministicReport" in the coverage settings file. More details in here https://github.com/microsoft/codecoverage/blob/main/docs/configuration.md
latop2604 commentedon Oct 9, 2025
Thx, but I don't think it will work, as gitlab will not be able to map it anymore to the real file path.
latop2604 commentedon Oct 9, 2025
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?fhnaseer commentedon Oct 10, 2025
No, it is not possible to override this.
latop2604 commentedon May 26, 2026
FYI, coverlet now support MTP. So switched back to it.