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

Pester "Should -Invoke does not take pipeline input or ActualValue"

I am using the following test code: Describe "Install-Programs"{ Context "Install-Programs"{ BeforeAll{ Mock Start-Process {} } It "Tests"{ My-CustomFunction #Should invoke Start-Process …
Kevin Holtkamp
  • 479
  • 4
  • 17
1
vote
1 answer

Clear Pester TestDrive manually

Is there a way to manually clear the pester TestDrive, other than something like Remove-Item "TestDrive:\" -Recurse -Force
Kevin Holtkamp
  • 479
  • 4
  • 17
1
vote
1 answer

Mocking functions with Pester not working

I have the following code in my Test: It "Set mock partitions"{ Mock Get-Disk { return [PSCustomObject]@{ SerialNumber = "SERIAL" } } Mock Get-Partition { param([PSCustomObject] $InputObject) …
Kevin Holtkamp
  • 479
  • 4
  • 17
1
vote
1 answer

Pester test if list is empty do not run the tests

I would like to be able to skip tests if list is empty. a very simplified example: No name is -eq to "jens", therefore the $newlist would be empty, and of course the test will fail, but how do i prevent it from going though this test if the list is…
Nadia Hansen
  • 697
  • 2
  • 6
  • 16
1
vote
1 answer

How to Pester-test a method in a class module (.psm1)?

I have written multiple classes. All of them are being used interchangeably. The main script (Main.ps1) imports some of them and runs the program. I'd like to create Pester tests for each one of these class modules (.psm1) that I've created,…
noobie
  • 411
  • 1
  • 12
1
vote
0 answers

How can I catch DriveNotFoundException error when invoking pester?

I have a powershell script, which in parallel, invokes instances of Pester, with: Invoke-Pester @{Path= "somepath/file.tests.ps1"; Parameters = @{... ...}} -Tag 'value' -OutputFile $xmlpath -OutputFormat NUnitXML -EnableExit There is often a run,…
user13800089
1
vote
1 answer

Synchronous unit test execution in Powershell

I've got a Pester It block, that looks like the below: It "should add a header" { { $DifferenceObject = Get-Content -Path $PathToFile1 Set-PowershellFile -Path $PathToFile2 $ReferencedObject = Get-Content -Path…
1
vote
1 answer

Pester Unit Test - Mock Get-ADUser Not Working as Expected

First of all I'll apologise if this isn't the correct way to ask these questions, this is my first time submitting to SO. The short version is : I have a script Get-SamAccountName.ps1 that takes Input Variables of a -FirstName, -LastName, -Format to…
1
vote
1 answer

Pester Unit Test for Get-AzureBlobStorage

I am trying to write a unit for a simple Azure function in Powershell function Get-AzureBlobStorage { param ( [Parameter(Mandatory)] [string]$ContainerName, [Parameter(Mandatory)] [string]$Blob, …
1
vote
2 answers

Mocking Response of a REST API in Pester

I have a PowerShell script that returns a string from a REST API call. I am using $Response = Invoke-RestMethod -Method Post -Uri $Uri -Body $Body -ContentType 'application/x-www-form-urlencoded' return $Response.ToString() I am able to mock the…
Zoltaire
  • 21
  • 3
1
vote
1 answer

How can I dynamically create and add tags in PowerShell script during Invoke-Pester command?

I have several Describe/It tests in a ps1 file called Behavior.Tests.ps1. Each test, however, can only run successfully on systems with specific hardware. I am aware that I can use tags like this in the Invoke-Pester command: Invoke-Pester $path…
NuclearFish
  • 69
  • 1
  • 4
1
vote
1 answer

What does the second number in Pester's coverage % mean?

When I run pester I get this output Covered 100% / 75%. 114 analyzed Commands in 1 File What does the 75% mean? I haven't been able to find it anywhere in the documentation.
Jack Weems
  • 13
  • 3
1
vote
1 answer

Adding owner to Pester test results

Is there a way to add an owner per test to the NUnit results exported by Pester? What I’m hoping to do is notify the owner via teams or email through an Azure devops pipeline (I don’t have this fully sorted yet). As a start I think I’ll need the…
1
vote
1 answer

How to test a function in ps with test explorer in vsc

I want to set up powershell script testing but also limit the scope to functions. myscript.ps1 contains internal functions with each their own parameter dependencies also, but I will not test them, only interested in Get-Something. How do I import…
user16908085
  • 95
  • 10
1
vote
1 answer

V5 -- Data driven Tags?

In a Pester v5 implementation, any way to have a data driven tag? My Use Case: Operating on larger data sets To have all tests runable on a data set To be able to run against a specific element of my data set via the Config Filter My Conceptual…