Skip to content

0% branch coverage when code has no branches #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FreedCapybara opened this issue Dec 10, 2018 · 7 comments
Closed

0% branch coverage when code has no branches #261

FreedCapybara opened this issue Dec 10, 2018 · 7 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@FreedCapybara
Copy link

FreedCapybara commented Dec 10, 2018

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!

@tonerdo tonerdo added bug Something isn't working help wanted good first issue Good for newcomers labels Dec 10, 2018
@pape77
Copy link
Contributor

pape77 commented Dec 12, 2018

this one I already fixed locally, pretty easily @tonerdo

On your CoverageDetails class:
just return 1 when Total is 0

 public double Percent
        {
            get => Math.Round(Total == 0 ? 1 : Covered / Total, 3);
        }

I also made it print Not applicable when Total is 0, so it shows nicely in the console output and you know why it's 100% overall branch coverage.

I had a lot to contribute, but I needed the #225 to be merged in for my pipelines (preferably without the options parameter, cuz it's something that should always happen). So I had to fork away

@FreedCapybara
Copy link
Author

Thank you!

@ghost
Copy link

ghost commented May 8, 2019

Hello Folks,

It seems this commit(85fa0f3) re-introduced the branch coverage issue.

Can we re-open this and fix it ?

Thanks

@p4p3
Copy link

p4p3 commented May 8, 2019

@FreedCapybara @tonerdo

@MarcoRossignoli
Copy link
Collaborator

@samajs which version are you using?

@MarcoRossignoli
Copy link
Collaborator

This PR fix the issue #267 and last days we simplify more with rounding #397

@ghost
Copy link

ghost commented May 9, 2019

@MarcoRossignoli my bad, just realised I am using coverlet.msbuild 2.0.1 but latest is 2.6.1, this one is fixed there.
Thanks for pointing out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants