triadagl.blogg.se

Pester code coverage
Pester code coverage











  1. #Pester code coverage how to
  2. #Pester code coverage software
  3. #Pester code coverage code
  4. #Pester code coverage series

It just reports that the Else clause of Test-LeapYear didn’t run.

#Pester code coverage code

So, you would expect the Code Coverage report to be pretty dismal, but it’s not too bad. Note that it tests only Get-Hello and only verifies that it returns “Hello, World.” I added Get-DateHelper so I could mock it and provide varying test input to Test-LeapYear. Get-DateHelper calls the Get-Date cmdlet.Test-LeapYear calls a Get-DateHelper function, then calls the IsLeapYear static method.Get-Hello function writes ‘Hello, World” and calls the Test-LeapYear function.To identify what the CodeCoverage parameter tests, let’s experiment. What does the Code Coverage parameter do? Oh, and if you use the Quiet parameter to suppress the host output of Invoke-Pester, it suppresses the Code Coverage report, too.

pester code coverage

However, NUnitXML and LegacyNUnitXML output that the OutputXML and OutputFormat parameters of Invoke-Pester use do not include any code coverage information, because it’s not supported by the schema. You can pipe the code coverage custom object to Export-Clixml or to ConvertTo-Json and then to Out-File. The custom object that Invoke-Pester returns has an additional CodeCoverage property that contains a custom object with detailed results of the code coverage test, including lines hit, lines missed, and helpful statistics. To save your Code Coverage report, use the PassThru parameter. 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."

pester code coverage pester code coverage

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.

#Pester code coverage software

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.

pester code coverage

“… 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.

#Pester code coverage how to

  • 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.
  • #Pester code coverage series

    This article 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













    Pester code coverage