FortuneN / FineCodeCoverage

Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)
https://marketplace.visualstudio.com/items?itemName=FortuneNgwenya.FineCodeCoverage
Other
516 stars 39 forks source link

Hide/Remove Projects/Classes/etc. from coverage #67

Open mmmasent opened 3 years ago

mmmasent commented 3 years ago

Installed product versions

Description

Unable to hide or remove coverage reports for unnecessary projects

Steps to recreate

  1. Run tests
  2. See code coverage report

Current behavior

Summary Code coverage for unit test projects are shown with calculations over entire solution

Expected behavior

Should be a way to hide/remove projects as needed and have coverage calculated only on desired projects fpr summary reporting i.e. Right click project, select hide from coverage report

Additionally, it'd be good to have the ability to readd projects as desired, if one were to go project by project inside a solution

Side Notes

Awesome extension

tonyhallett commented 3 years ago

Unable to hide or remove coverage reports for unnecessary projects

The Exclude project element or Fine Code Coverage option is there for this reason. You can apply an exclusion attribute in a project as well.

Right click project, select hide from coverage report

We could do that but I don't think that it would be silent.

Additionally, it'd be good to have the ability to readd projects as desired, if one were to go project by project inside a solution

Are you thinking of an option - filter report by selected project. Then dependent upon the selected project in solution explorer we filter to only show that filter ?

mmmasent commented 3 years ago

I understand fine code coverage is not ReSharper, but I am coming from a ReSharper background. image

When you run code coverage with ReSharper, it also includes test projects in the code coverage, but you can exclude tests from the summary without needing an attribute of any kind. You can simply right click and click remove.

A filter of some kind would achieve what I am thinking of as well.

tonyhallett commented 3 years ago

You can exclude test projects with IncludeTestAssembly as a global visual studio option or on a project basis.

wdspider commented 3 years ago

Is there a way to get Fine Code Coverage to use the include/exclude settings I've already defined within my *.runsettings file instead of requiring them to be re-setup within Fine Code Coverage vs options?

Nordes commented 3 years ago

I simply use the [ExcludeFromCodeCoverage] over a class or method. If anyone was wondering how to do in C#.

{
    [ExcludeFromCodeCoverage] // <== this line
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
craigktreasure commented 1 year ago

This appears to work at the class level, but not for methods. Methods marked with the ExcludeFromCodeCoverage attribute aren't excluded from the code coverage calculation.

tonyhallett commented 1 year ago

@craigktreasure Is this only when using ms code coverage ?

craigktreasure commented 1 year ago

Hmmm...good question. Not sure. I have RunMsCodeCoverage set to No in the FCC settings.

tonyhallett commented 1 year ago

@craigktreasure ExcludeFromCodeCoverage should work on methods. Do you have a repo that I can look at ?

craigktreasure commented 1 year ago

Not that I can quickly share. To be clear, what i'm seeing is that the Fine Code Coverage window doesn't properly reflect excluded methods. For that matter, it's the same for assemblies marked with ExcludeFromCodeCoverage.

The reports I generate using Coverlet are correct. It's just the Fine Code Coverage window that doesn't reflect properly.

tonyhallett commented 1 year ago

FCC uses Coverlet version 3.0.3 and a fork of https://github.com/danielpalme/ReportGenerator.

All cobertura files ( multiple test projects ) are merged into a single one by ReportGenerator and this is then used to generate the report in the Find Code Coverage tool window.

Perhaps you can compare your Coverlet report with the coberturas within

...YourProject\bin\Debug\net6.0\fine-code-coverage\coverage-tool-output

YourProject.coverage.xml is generated by Coverlet Cobertura.xml is the merged version.

The issue could be the Coverlet version, now at 3.1.2, or ReportGenerator. The next FCC release creates its own html report displaying it in a WebView2 control and as such can use the latest version of ReportGenerator which dropped support for ie and the WebBrowser control.

tonyhallett commented 1 year ago

@craigktreasure If you can create a minimal reproduction I will have a look.

tonyhallett commented 1 year ago

@craigktreasure Latest release updates Coverlet to 3.2.0. Does this resolve your issue ?

craigktreasure commented 1 year ago

Yep. It does seem to have resolved the issue. Thanks!