Skip to content

0% branch coverage when code has no branches #261

@FreedCapybara

Description

@FreedCapybara

Hi,

Small issue I noticed while playing around with Coverlet is that for code with no branches, 0% branch coverage is reported instead of 100%.

ConsoleApp1.csproj
Program.cs

using System;

namespace ConsoleApp1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

ConsoleApp1.Tests.csproj
UnitTest1.cs

using System;
using Xunit;

namespace ConsoleApp1.Tests
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            Program.Main(new string[] { });
        }
    }
}

Output

Test run for C:\src\ConsoleApp1\ConsoleApp1.Tests\bin\Debug\netcoreapp2.1\Consol
eApp1.Tests.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1.7762 Seconds

Calculating coverage result...
  Generating report 'C:\src\ConsoleApp1\ConsoleApp1.Tests\coverage.opencover.xml
'

+-------------+--------+--------+--------+
| Module      | Line   | Branch | Method |
+-------------+--------+--------+--------+
| ConsoleApp1 | 100%   | 0%     | 100%   |
+-------------+--------+--------+--------+

Total Line: 100%
Total Branch: 0%
Total Method: 100%

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions