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
503 stars 38 forks source link

Feature - Generate own report from cobertura #49

Open tonyhallett opened 3 years ago

tonyhallett commented 3 years ago

If dotnet-reportgenerator-globaltool changes its internal data structure then the report window will no longer work

tonyhallett commented 3 years ago

Background for anyone taking on this feature.

Code required to understand own report generation

https://github.com/coverlet-coverage/coverlet/blob/fe6fee996889ac3a5e98f786ad94262260db79a4/src/coverlet.core/Reporters/IReporter.cs#L8

Here are built in reporters https://github.com/coverlet-coverage/coverlet/blob/fe6fee996889ac3a5e98f786ad94262260db79a4/src/coverlet.core/Reporters/ReporterFactory.cs

The cobertura reporter https://github.com/coverlet-coverage/coverlet/blob/fe6fee996889ac3a5e98f786ad94262260db79a4/src/coverlet.core/Reporters/CoberturaReporter.cs


https://github.com/FortuneN/FineCodeCoverage/blob/266ca4fe0ec5ac06b8c848df08e06a5d856609a6/FineCodeCoverage/Core/Cobertura/CoberturaUtil.cs#L85


        public static CoverageReport ProcessCoberturaXmlFile(string xmlFilePath, out List<CoverageLine> coverageLines)
        {
            coverageLines = new List<CoverageLine>();

            var report = LoadReportFile(xmlFilePath);

                        // the report is deserialized cobertura - create report from it !

            foreach (var package in report.Packages.Package)
            {
                foreach (var classs in package.Classes.Class)
                {
                    foreach (var line in classs.Lines.Line)
                    {
                        coverageLines.Add(new CoverageLine
                        {
                            Package = package,
                            Class = classs,
                            Line = line
                        });
                    }
                }
            }

            return report;
        }

The unified xml is deserialized in to the CoverageReport class.

It should be relatively simple to create a wpf table that replicates the html report

tonyhallett commented 3 years ago

Further background https://github.com/coverlet-coverage/coverlet/issues/1028 https://github.com/danielpalme/ReportGenerator/issues/402

tonyhallett commented 3 years ago

@FortuneN

Further to our video call discussion where it was desired for the microserver to return the report in a generic format. I was thinking using json over xml as would be better for html report generation.

The change could be as simple as

//unifiedJson - report type and path to change, may even be beneficial providing a custom IReportBuilder.  Can remove
//autogenerated classes with the report generator class filter.
ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedJson, out var unifiedXmlFile, true); 

//new method
//this will just set a var on the page to be processed by javascript again calling back through window.external
GenerateHtmlFile(unifiedJson,darkMode,out var coverageHTML )

A) Do you want to continue using an html file in visual studio ? If so How would you like the js ? Vanilla, knockout or react ? If the latter do you want scripts embedded in the page ? How would you like this tested ? Puppeteer or something specific to framework if used ? Do you want to leave it up to me ? I will replicate current functionality with the addition of branch coverage. If desired I can add the grouping and filtering that report generator provides. image Later can incorporate visual studio options for the report display.

I am good to do this tomorrow.