POV: I'm generating Powershell test code coverage with pester.
Problem: The generated Coverage.xml file remains empty.
Question What am I doing wrong?
Some technicalities:
Write-Verbose -Message "Running Pester Tests"
$conf = New-PesterConfiguration
$conf.Run.Path= ".\Tests\"
$conf.Run.TestExtension = '.Unit.Test.ps1'
$conf.Output.CIFormat = "AzureDevops"
$conf.TestResult.Enabled = $true
$conf.TestResult.OutputPath = './TestResults/Testresult.xml'
$conf.CodeCoverage.Enabled = $true
$conf.CodeCoverage.OutputFormat = 'JaCoCo'
$conf.CodeCoverage.CoveragePercentTarget = 70
$conf.CodeCoverage.RecursePaths = $true
$conf.CodeCoverage.OutputPath="./TestResults/Coverage.xml"
$conf.CodeCoverage.Path=".\Tests\*.Unit.Test.ps1"
Invoke-Pester -Configuration $conf
> Get-Module Pester | Where-Object {$_.Version -gt '5.0.0'}
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 5.4.0 Pester {Add-ShouldOperator, AfterAll, AfterEach, Assert-MockCalled…}
> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Changing this
to
made it work.
The documentation is really obscure about this: https://pester.dev/docs/commands/New-PesterConfiguration
The general settings say: path to test files. CodeCoverage says: path from general settings is used..
This made me believe CodeCoverage should point to the test files.
Yet their default settings don't even work.
This put me on the wrong track.
Thanks to Daniel for putting me on the correct track.
Correction
The file is generated, yet the coverage is incorreclty always 0%