Microsoft: Testing PowerShell with Pester
As PowerShell scripts become more and more important to organizations, simply eyeballing the results a few times and confirming that they do not return an error isn’t good enough. Especially if the PowerShell code you write is maintaining production systems, it’s critical that some extra steps are taken to run that script through many different scenarios to ensure it’s rock-solid. The way to do this is by creating Pester unit tests.
Pester is an open source unit testing framework developed specifically to test PowerShell code. It is a PowerShell module that is used to write tests for PowerShell code to confirm that what it does is what you expect. In a nutshell, Pester is the code that’s written “on top of” your code to act as quality assurance. Fortunately, Pester itself is written in PowerShell, so you don’t have to be a software developer to learn how to use it. As long as you can learn a few syntactical differences between vanilla PowerShell and Pester, you’ll be okay.
Note: Before we get too far here it’s important we clarify “tests.” In our case, we’re going to be focusing on unit tests. These kinds of tests differ from other types of tests you might hear thrown around like infrastructure, integration or acceptance tests. The primary difference is that unit tests test the code itself while the other kinds of tests test how that code interacts with the environment. If you’d like an example of infrastructure testing, check out my Infrastructure Testing with Pester talk.
Read the entire article here, Testing PowerShell with Pester – Microsoft MVP Award Program Blog
via the fine folks at Microsoft