Table of Contents
Let’s take a look at Pester configuration for this project, as an example of how you can integrate this tool with Pester to run automatically.
config.ps1 (constUP JaCoCo XML to HTML configuration file):
$Global:jacocoxml2htmlConfig = [PSCustomObject]@{
'xml_file' = "$PSScriptRoot\coverage\coverage.xml";
'destination_directory' = "$PSScriptRoot\coverage\html";
'sources_directory' = "$PSScriptRoot\src";
}
pester.ps1 (Pester configuration file):
$config = New-PesterConfiguration
$config.TestDrive.Enabled = $true
$config.TestRegistry.Enabled = $true
$config.Run.Path = "./tests"
$config.CodeCoverage.RecursePaths = $true
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = './src'
$config.CodeCoverage.OutputPath = './coverage/coverage.xml'
$config.CodeCoverage.OutputFormat = 'JaCoCo'
Invoke-Pester -Configuration $config
. ("$PSScriptRoot\config.ps1")
if (Test-Path -Path $Global:jacocoxml2htmlConfig.destination_directory) {
Remove-Item -Path $Global:jacocoxml2htmlConfig.destination_directory -Recurse -Force
}
& .\constup-jacoco-xml-to-html -config .\config.ps1
Everything up to Invoke-Pester
is default Pester configuration.
Invoke-Pester
will run Pester tests and generate XML coverage report in JaCoCo format. After it finishes and generates
the report, we are:
-
Loading JaCoCo XML to HTML configuration in order to grab a destination directory;
-
Deleting the destination directory;
-
calling the HTML generator to generate HTML;
Loading the configuration and deleting the destination directory is optional and depends on your needs.