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
2
votes
1 answer

How to make the output in the pipeline appear on the console when running pester tests?

By default, the output in the pipeline is hidden,But sometimes I really want to know the output at that time. Of course, I knew I could add additional commands, such as write-host or out-default. But does Pester itself have a mechanism to make the…
Andy
  • 1,077
  • 1
  • 8
  • 20
2
votes
1 answer

Checking Windows Disk Encryption with Pester

I am trying to test the Protection Status of local disks on Windows Server with Pester using the following Pester code: Describe 'Encryption Check' { $Diskencr = Get-BitLockerVolume $Diskencr.ForEach{ write-host $_.ProtectionStatus …
2
votes
1 answer

Can Pester Mock [Type]::new()

I have script that has the following code: $var1 = [TESTType]::new($Var) I would like to run a pester test that Mock [TESTType]::new($Var). Is This possible ?
user7786267
  • 137
  • 12
2
votes
1 answer

How to handle multiple key press simultaneously in powershell? Eg:Windows logo key + Alt + PrtScn:

Tried the below code in powershell ISE but it accept only 1st key (Pressing Win) after that it accepts next key as 'g'.…
GKA
  • 23
  • 2
2
votes
0 answers

How to pass parameters for each test case in pester?

I have a powershell script in azure Invoke-Pester -Script @{Path = 'C:\Turing\Test\Frida-launcher.ps1'; Parameters = @{frida_process_id = '1655944245'; frida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -OutputFile "frida-results.xml"…
Heber Solis
  • 437
  • 1
  • 6
  • 15
2
votes
3 answers

Powershell Unit test cases

I have a command in powershell and I am calling same command two times and I am expecting first time it will return a value and second time it will throw a error , any idea how to test this block of code? how can I provide multiple implementation…
IronManUTF8
  • 57
  • 1
  • 5
2
votes
0 answers

How to save attachments and standard output with a pester unit test?

I would like to attach files and standard output to a Pester unit test. I run pester with NUnit output format, so that it could be published to our Azure DevOps server. But it does not seem to capture any output nor let me attach files - something…
mark
  • 59,016
  • 79
  • 296
  • 580
2
votes
1 answer

Can I use If/Else statement in Pester?

I want to test a function when it succeeds but also whether it throws the correct error when it fails. I wrote a function Test-URLconnection which should test whether a URL is accessible, otherwise it should throw an error. Describe…
Alex_P
  • 2,580
  • 3
  • 22
  • 37
2
votes
2 answers

Test for `pester` version using `pester`

I have a set of pester tests for a PowerShell module which use the v4.0+ should operator -FileContentMatch. When these tests are run on a machine with an earlier v3.x version of pester, there is a wave of error messages, none of which exactly point…
rivy
  • 1,570
  • 1
  • 15
  • 30
2
votes
1 answer

How do I mock $host.ui.PromptForChoice with Pester

Considering the below Powershell code, is there a way to mock $host.ui.PromptForChoice without the internalMenuWrapper function? <# .Synopsis wrap the menu so we can mock calls to it #> function internalMenuWrapper { param ( …
Dave Neeley
  • 3,526
  • 1
  • 24
  • 42
2
votes
2 answers

How can i mock the contents of a .cs file with Pester allowing me to iterate through each line and each character?

Short description: I'm trying use Pester to mock the contents of a file and then iterate through each line and each character of that fake data, but I'm getting this error: "the array index evaluated to null." when trying to access the characters of…
Emiliano Rodriguez
  • 454
  • 2
  • 6
  • 19
2
votes
1 answer

Mock write-verbose not working when with invoke-pester

The below script works when ran with a dot but fail to run when called with invoke-pester (running Pester version 4.6.0). Am I doing something wrong or is there an issue with invoke-pester? using module "./Test.psm1" Describe "Unit Test" -Tag…
user7786267
  • 137
  • 12
2
votes
1 answer

is start-bitstransfer compatible with pester

When running start-bitstransfer in a script I'm trying to apply pester to... it doesn't seem to work... I just tried downloading some random http page (while preparing to do some tropico 5 ;) ... to the pester testdrive, but this doesnt work... do…
2
votes
4 answers

How to compare two arrays with custom objects in Pester

We're struggling to have Pester tests fail or pass depending on the equality of objects within an array. Test.ps1 #require Assert #require Pester $Expected = @( [PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'} [PSCustomObject]@{Name1 =…
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
2
votes
1 answer

How to properly Pester test Import-Clixml

So first of all I need to state that I am quite new to Pester and might not be writing my tests correctly or don't properly understand all its functionality. So background is that I want to automate my PowerShell module with Pester and have written…
Tsteenbakkers
  • 264
  • 3
  • 18