Since December 2023, Microsoft has added support to Microsoft.CodeCoverage and dotnet-coverage for exporting code coverage data in the Cobertura format (see the announcement here).
1 2 |
dotnet test --results-directory "test-results" --collect:"Code Coverage" dotnet test --results-directory "test-results" --collect:"Code Coverage;Format=cobertura" |
Because NDepend imports code coverage data, some users have requested support for the Cobertura format. The latest NDepend version 2024.2.1, now includes support for the Cobertura format. However, we’ve noticed an issue: Cobertura is less accurate compared to the more widely used coverage formats in .NET. Cobertura only indicates whether a line of code is fully or partially exercised by tests. In contrast, other standard .NET formats specify the exact covered portions within a line, known as sequence points.
The difference in accuracy is illustrated in the screenshots below, comparing two NDepend web reports: one generated using Cobertura and the other with OpenCover.
Originally designed for Java projects, Cobertura is a popular XML-based code coverage format supported by many tools like Jenkins. This likely explains why Microsoft enabled to export to Cobertura. However, if your .NET team can use a .NET-specific format, it’s generally a better choice for accuracy.
You might be interested to read: A Guide to Code Coverage Tools for C#