Questions tagged [pester]

Pester is a unit test framework for PowerShell. It provides a domain specific language that allows you to define test cases. It is also used to perform operational/infrastructure testing and this is encouraged by Microsoft who leverage Pester as part of the Operation Validation Framework project.

Per the Pester project page:

Pester provides a framework for running unit tests to execute and validate PowerShell commands from within PowerShell. Pester consists of a simple set of functions that expose a testing domain-specific language (DSL) for isolating, running, evaluating and reporting the results of PowerShell commands.

See

302 questions
1
vote
1 answer

Can Pester and/or Mock be used to test a .ps1 script?

Consider a .ps1 script that takes parameters and makes state changes. There are two aspects of the script I'd like to test: Parameters are received from caller, typed, and sorted into parameter sets according to expectations Key internal function…
John Doggett
  • 137
  • 2
  • 7
1
vote
2 answers

Pester mocks are pestering me

I am an utter newbie regarding PowerShell and am now tasked to write unit tests for some existing PowerShell scripts. It is a great task for me to learn about automating unit tests but have no idea where to begin. I followed several trainings about…
1
vote
1 answer

Invoke Pester returning with zero results

I have a Pester Script with is running a few smoke tests for my API. When I run the Invoke-Pester, I get the Logo and the tests run fine. However at the end of the log I get Tests Passed: 0, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0 and…
Ross
  • 2,463
  • 5
  • 35
  • 91
1
vote
3 answers

How to mock a command called twice with different parameters and different results

I have a PowerShell function I want to test with Pester: function Install-RequiredModule ( [string]$ModuleName, [string]$RepositoryName, [string]$ProxyUrl ) { # Errors from Install-Module are non-terminating. They won't be…
Simon Elms
  • 17,832
  • 21
  • 87
  • 103
1
vote
2 answers

Can I use Pester to mock/verify to cmdlets without parameters names?

I'm using several Powershell scripts with Advanced Installer 15.1 that I wish to test using Pester. Advanced Installer provides two Cmdlets in order to access MSI variables from Powershell scripts, AI_GetMsiProperty and AI_SetMsiProperty, which I…
pghprogrammer4
  • 898
  • 2
  • 9
  • 21
1
vote
2 answers

Global Mock with Pester PowerShell

I have used PesterHelpers to construct a suite of tests for my module and have begun adding Functional tests. I run the min, norm, and full test scripts as needed to test my work. I find that I am using the same mocks over and over, copying them…
1
vote
0 answers

Pester Gherkin Test: "Cannot find a variable with the name 'PSBoundParameters'"

I came across a utility function: Get-ParameterValues, by @Jaykul, along with a slightly modified version by elovelan. I chose to use elovelan's version which doesn't declare parameters. I can confirm that, as far as I've tested at the command line,…
fourpastmidnight
  • 4,032
  • 1
  • 35
  • 48
1
vote
1 answer

Powershell Mock a module with matching param returns null

I'm attempting to use Powershell to mock Join-Path with in a module. This mock will return a TestDrive location but I keep getting $null instead of the TestDrive location. In my example module $OutputPath returns with null. What am I doing wrong…
Eric
  • 53
  • 3
1
vote
1 answer

Can I bypass permissions in Powershell?

I am testing a script in Powershell using pester, however I can't see if the script works or not because I keep getting access denied to certain files. Is there anyway to bypass this just so I can see if my script works or not? Thanks Edit: my…
1
vote
4 answers

"Path cannot be found" Pester Test Results

Im testing out a script on Pester. I keep getting a Path cannot be found error. Apparently something is wrong with some of my lines. $userFolders = Get-ChildItem C:\Users -Directory foreach($folder in $userFolders) { Get-ChildItem…
techguy1029
  • 743
  • 10
  • 29
1
vote
1 answer

How to write Pester Unit Test for ranges of values with multiple decimals

I have a PowerShell function that returns value with multiple decimals from a range of values. How do I write Pester unit test for this kind of function. This kind of function is used to check version of some of applications like Outlook. function…
1
vote
1 answer

Read the values from properties file in pester

I want to read the data from properties file in powershell using pester framework, but facing an error. Properties file: vmsize1='Standard_D3_V2' vmsize2='Standard_DS1_V2' Code: Context "VIRTUAL MACHINE" { $file_content = get-content…
Parth Makwana
  • 51
  • 1
  • 9
1
vote
1 answer

Pester test if the module is existing. Should not throw specific ExceptionType

Is it only me or the Pester if extremely hard to grab? In the BeforeAll scriptblock I would like to test if the ActiveDirectory module is existing on the local machine. The test should not throw exception type…
pandemic
  • 1,135
  • 1
  • 22
  • 39
1
vote
1 answer

Pester Assert-MockCalled counts wrongly

writing some tests with Pester and Powershell Code: Import-Module Module Import-Module Pester InModuleScope Module{ Describe 'Add-Patchgroup' { Context 'Add_server_to_group_fail' { Mock Add-ADGroupMember {throw…
pandemic
  • 1,135
  • 1
  • 22
  • 39
1
vote
2 answers

Dealing with Arrays in Powershell (testing with Pester)

I have a little trouble understanding the way to implement this process. I want to achieve a total count in the score so that if a test successfully passes or fails it can be added into an array. That array will be counted in the length. This is my…