The primary output already tells you which tests ran.īy default, Invoke-Pester writes the code coverage report to the host program (like Write-Host), so you can’t save it in a variable, redirect it, or pipe it to a file. You want the Code Coverage report to make sure the code in your script ran. But, be careful! Enter the path to the code being tested not the path to the test file.įor example, if you have Get-Script.ps1 and its test file, 1, the value of the Script parameter is 1, but the value of the CodeCoverage parameter is Get-Script.ps1. In its simplest form, it takes a path string. It seems like -CodeCoverage should be a switch parameter, but it requires strings and/or hash table values. Hello.ps1 Test-LeapYear 30 Write-Warning "$($date.Year) is not a leap year." Code coverage report:Ĭovered 77.78 % of 9 analyzed commands in 1 file. A code coverage report lists the lines of code that did and did not run during a Pester test. The CodeCoverage parameter of Invoke-Pester adds a code coverage report to the tests that Pester runs. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage…”īut, at least in this case, I found out that it’s a measure of the code that runs during a test not the degree to which the code is tested or anything about the quality of the test. “… describe(s) the degree to which the source code of a program is tested by a particular test suite. To run it, you use the CodeCoverage parameter of Invoke-Pester. How to Pass Parameters to a Pester Test ScriptĪmong the many amazing features of the Pester test framework for PowerShell is a code coverage test.This post is the fourth in a series about how to run Pester tests. Code coverage reports are really valuable, but you need to understand what they test and how to use them. It doesn’t mean that 100% of my code is tested. I’m one of those people who thinks a score of 99% is failing, so I love to see those 100% scores when I use the CodeCoverage parameter of Invoke-Pester.īut, while assembling my Pester presentations for DevOps Global Summit 2016 and PowerShell Conference Europe 2016, I realized the 100% code coverage score means that 100% of my code (every line) ran during the test. Applies to: PowerShell 6.122, 7, Pester 3.4.0
0 Comments
Leave a Reply. |