NDepend Blog

Improve your .NET code quality with NDepend

The Issue with using the Cobertura Code Coverage Format in .NET

November 14, 2024 1 minutes read

Cobertura Code Coverage Format in DotNet

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).

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.

Cobertura recognizes only the concept of lines. .NET formats like OpenCover, dotCover and VS Coverage (binary or XML) rely on sequence points, defining coverage with start and end lines as well as start and end columns.

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#

Leave a Reply

Your email address will not be published. Required fields are marked *