microsoft / microsoft/codecoverage
Support GitLab-compatible Cobertura format in MTP natively
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 125
- Forks
- 17
- Avg merge
- 1h 17m
- Merged PRs (30d)
- 2
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!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- csharp
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100