Skip to content

[Improvement] GitVersion generated code should not participate in code coverage #2305

@odalet

Description

@odalet

Summary

I use GitVersion through its MSBuild task. Yesterday by running "code coverage" from Visual Studio, I noticed, the generated GitVersionInformation class was considered as not covered code. Well, it's generated code and therefore It'd make sense for it not be part of the coverage statistics:

image

Detailed Description

Visual Studio (Enterprise) coverage facility uses compiled assemblies to compute code covered by unit tests statistics. Hence, even though GitVersionInformation wasn't written by the user, it appears in coverage results. I suspect it would be the same for other .NET coverage tools. This kind of code twists the coverage results (if only by a very tiny bit). It would be more correct to exclude it from coverage analysis.

Context

Honestly, this is not a must-have. I can live with a little discrepancy in my coverage resutls. However, I suppose changing this would be desirable for accuracy and correctness purpose.

Possible Implementation

The change should be rather straightforward (and I'm about to submit a PR for this): one only needs to add the ExcludeFromCoverage attribute on top of the generated code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions