concept Pester in category powershell

This is an excerpt from Manning's book Learn PowerShell Scripting in a Month of Lunches.
Many times, in testing, you’ll want to have some command seem to run, but not run. For example, you might need to have Import-CSV import a specific CSV file, but you don’t want to create the file. Or, in our case, we want Restart-Computer to seem to run, so we can figure out if our code tried to run it, but we by no means want to restart a computer. This is where Pester’s mocking comes into play. It basically creates a fake replacement for an existing command, and that fake can do whatever you like:
Describe "Set-ComputerState" { Mock Restart-Computer { return 1 } Mock Stop-Computer { return 1 } It "accepts one computer name" { Set-ComputerState -computername SERVER1 -Action Restart | Should Be 1 } }Our fake version of Restart-Computer will now output 1. It won’t restart any computers—it’ll just output 1. And so, if it’s called one time, the result of Set-ComputerState should be 1. We’ve told Pester as much with our It block. Let’s try running this simple test to see whether it works. From our example folder, which contains our tests script, we have to run Invoke-Pester:
Pester (PowerShell Tester, sort of) is an open source project that’s bundled with Windows 10 and later (newer versions can be found in the PowerShell Gallery). It’s an automated unit-testing framework for PowerShell. In other words, you write your tests in Pester, and Pester runs your tests for you. Pester’s basic documentation is in the wiki of its GitHub repository, at https://github.com/pester/Pester/wiki.