In this post, I will show you how to generate an HTML report from the code coverage file generated by Pester 5 tests.
First, we need to generate a code coverage file using Pester 5.
$pesterArgs = [PesterConfiguration]::Default
$pesterArgs.Run.Path = '.'
$pesterArgs.Output.Verbosity = "Normal"
$pesterArgs.CodeCoverage.Enabled = $true
$pesterArgs.CodeCoverage.Path = ".\*.ps*1"
$pesterArgs.CodeCoverage.OutputFormat = 'JaCoCo'
$pesterArgs.CodeCoverage.OutputPath = "coverage.xml"
Invoke-Pester -Configuration $pesterArgs
After running this code you will have a coverage.xml file in JaCoCo format that can be used with Report Generator to create an HTML file. From the NuGet page for Report Generator I downloaded the package and changed the extension from ".nupkg" to ".zip". Now I can double click on the file to see its contents. In the tools folder, you will find several versions.
Copy the folder that matches the version of .NET you have installed on your machine and paste it in a location so we can execute ReportGenerator.exe on our coverage.xml file. On my machine, I pasted it in "F:\temp\reports".
With Report Generator on my machine, I ran the following command from the folder with my source and coverage.xml file.
F:\temp\reports\net5.0\ReportGenerator.exe -reports:*.xml -targetdir:.\reports -reporttypes:'Latex;Html' -sourcedirs:.\
This command generated an HTML report and stored it in a reports folder. Double-clicking on the index.html file shows this report.