Search code examples
powershellpester

What does the second number in Pester's coverage % mean?


When I run pester I get this output

Covered 100% / 75%. 114 analyzed Commands in 1 File

What does the 75% mean? I haven't been able to find it anywhere in the documentation.


Solution

  • It is the value of $PesterPreference.CodeCoverage.CoveragePercentTarget.Value, i.e the minimum amount of test coverage you want to achieve. This is set to 75% by default.

    It's mentioned on the page describing New-PesterConfiguration:

    CoveragePercentTarget: Target percent of code coverage that you want to achieve, default 75%. Default value: 75

    But it was quite hard to figure out, and it could do with being added to the documentation page about test coverage. I ended up searching through the source code and found that the message you listed is output here:

    CoverageMessage   = 'Covered {2:0.##}% / {5:0.##}%. {3:N0} analyzed {0} in {4:N0} {1}.'
    

    Which is populated with values here:

    $coverageMessage = $ReportStrings.CoverageMessage -f $command, $file, $executedPercent, $totalCommandCount, $fileCount, $PesterPreference.CodeCoverage.CoveragePercentTarget.Value