microsoft / microsoft/codecoverage
False positive branch coverage
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 125
- Forks
- 17
- Avg merge
- 1h 17m
- Merged PRs (30d)
- 2
Description
Class under test
namespace CoverageTest;
public static class Class1
{
public static int Test1(int n)
{
if (n < 10)
n = Random.Shared.Next();
return n;
}
}
Test class
using Xunit;
namespace CoverageTest.Tests;
public static class Class1Tests
{
[Fact]
public static void Test1()
{
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
<method line-rate="1" branch-rate="1" complexity="2" name="Test1" signature="(int)">
<lines>
<line number="6" hits="1" branch="False" />
<line number="7" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="8" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="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).
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 with MicrosoftCoverageTest.zip and run the shown dotnet test command against Class1.Test1. Compare the generated Cobertura report with the single executed path in the test; done means the report no longer marks both branch outcomes as covered for this reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100