Skip to content

False positive branch coverage #218

Description

Class under test

namespaceCoverageTest;publicstaticclassClass1{publicstaticintTest1(intn){if(n<10)n=Random.Shared.Next();returnn;}}

Test class

usingXunit;namespaceCoverageTest.Tests;publicstaticclassClass1Tests{[Fact]publicstaticvoidTest1(){Class1.Test1(2);}}

Command executed

dotnet test -verbosity:diagnostic -c Debug --collect:"Code Coverage;IncludeTestAssembly=False;Format=cobertura;CoverageFileName=R:\coverage\CoverageTest.Tests\cobertura.xml"

Excerpt from coverage results

<methodline-rate="1"branch-rate="1"complexity="2"name="Test1"signature="(int)">
<lines>
<linenumber="6"hits="1"branch="False" />
<linenumber="7"hits="1"branch="True"condition-coverage="100% (2/2)">
<conditions>
<conditionnumber="0"type="jump"coverage="100%" />
</conditions>
</line>
<linenumber="8"hits="1"branch="False" />
<linenumber="9"hits="1"branch="False" />
<linenumber="10"hits="1"branch="False" />
</lines>
</method>

The branch is executed only once, so it should not be possible to have coverage of both sides of the branch (taken and not-taken).

MicrosoftCoverageTest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions