![]() If you want to know more about Pester, go to github Wiki. Next part of this series will include other functionality of Pester. (Get-Ciminstance Win32_OperatingSystem | Select-Object FreePhysicalMemory).FreePhysicalMemory/1mb | Should BeGreaterThan 4 It "C drive free space greater than 20 GB" ).FreeSpace/1GB | Should BeGreaterThan 20 (Get-Service -Name MpsSvc).Status| Should Be Running ![]() You may use this drive to isolate the file operations of your test to a temporary store. But there is a really specific problem in PowerShell 2.0 that might make your tests act strangely. A simple example to start from Below is a shortened and simplified example of the tests I was writing. Pester is PowerShell 2.0 compatible and as long as PowerShell 2.0 will be relevant Pester will support it. Actually, calling the real Test-Path function could cause several issues in testing. In this post we take a look at a simple unit test example in Pester, and how we can evolve it to become better. Pester will remove this drive after the test completes. For example, let’s say your script calls Test-Path to validate the existence of a file. (Get-Service -Name VSS).Status| Should Be Stopped Pester creates a PSDrive inside the user's temporary drive that is accessible via TestDrive: or TestDrive. For that Should command is used – it compare result of code in It block with expected result. Command included in It block will throw an error in case that test of command will fail. It – should be used inside of Describe or Context commands. Usually used to group specific types of test (in my example services, disk space, RAM). The first task is building the code to test for this scenario. If the service is stopped, that's a problem, and you'd like to know about it. To use an example, let's say you have a Windows service that you expect to be running on all of your servers. In addition, the importance of having good requirements was stressed. Pester can test for anything PowerShell can read. The types of testing, unit, integration, and acceptance were discussed. For example, in this situation, I'd like to run some tests to ensure my function follows each of the two code paths it has: when Name is foo and when it is not. Test cases work great when testing a function that has various input parameters. I want to share with you basic example of using Pester commandlets.ĭescribe – define name of the test group under which Context and It blocks exists.Ĭontext – define grouping of It blocks. In part 1 of this series, Introduction to Testing Your PowerShell Code with Pester, I covered the basics of using the Pester module to test your PowerShell code. For this example, I'll use Pester's test cases functionality. Pester is quite fresh framework which is user friendly and very easy in implementation. Pester 5 was released a couple of days ago which brings a lot of new features and changes to how we write tests. Today let’s talk a little bit about framework for Powershel script testing called Pester. Pester can measure how much of your code is covered by tests and export it to JaCoCo format that is easily understood by build servers.
0 Comments
Leave a Reply. |