Questions tagged [pester-5]

30 questions
4
votes
2 answers

Why does Pester in Classic Azure Pipeline always fail?

I have a classic build pipeline (not yaml, yet!) with three tasks Install Pester -> works as expected Run Pester tests -> always fails! Publish test results -> works as expected My script for "Run Pester tests" Import-Module Pester -Force $config…
tomwaitforitmy
  • 509
  • 3
  • 16
3
votes
1 answer

Use a PowerShell hash's key/values with Pester TestCases

I would like to pass the key/values of a PowerShell hash to a Pester unit test, via the TestCases parameter: BeforeAll { $Expected = @{ Address1='Address1' Address2='Address2' City='City' RegionCode='RegionCode' …
craig
  • 25,664
  • 27
  • 119
  • 205
3
votes
2 answers

PowerShell Pester Mock Rest API Calls

Is there any simple approach on how to mock a Rest API Calls in Pester. Here is my code, I just need to mock those Rest API Calls in Pester and test them, could someone help me here. Describe 'Test worldclockapi.com' { BeforeAll { …
Atdhe Kurteshi
  • 373
  • 5
  • 14
3
votes
2 answers

Pester 5 variable scoping issue - BeforeDiscovery/It

Edit The crux of the question is: how do I get access to variable(s) declared in a BeforeDiscovery block in my It blocks that are not passed through by the it -foreach $var construct? I'm having difficulties adjusting to the Discovery/Run phase and…
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
3
votes
1 answer

Pester 5.0.2 BeforeAll block code not showing up in Describe block

I recently switched over to Pester 5.0.2 to start doing some testing on a Powershell script I wrote. I am able to break into the BeforeAll block and the paths are being populated as I would expect, however when I get to the Get-ChildItem area in my…
Efie
  • 1,430
  • 2
  • 14
  • 34
2
votes
2 answers

Is there any way to test functions in a PowerShell script without executing the script?

I would like to define stand-alone functions in my PowerShell script and be able to Pester test the functions without executing the rest of the script. Is there any way to do this without defining the functions in a separate file? In the following…
successhawk
  • 3,071
  • 3
  • 28
  • 44
2
votes
1 answer

Pester ignores mock

Given my powershell code (not in a function, as the last few parts are the script running, but i want to check some stuff for my script, using pester) My powershell code WinVersion.ps1 $WindowsVersion = Get-CimInstance -ClassName…
eagle00789
  • 53
  • 6
2
votes
1 answer

Pester Should -Throw does not catch error

This is the same problem and solution as this, but with simpler examples and hopefully easier to find, since it took me hours to find the above question. I have the following code that I want to test: Test-Function(){ {...} if($ExitCode -ne 0){ …
Kevin Holtkamp
  • 479
  • 4
  • 17
1
vote
1 answer

Passing parameter to Pester -testcases

I am trying to figure out the best way to parameterise my Pester (V 5.3.3) testcases. The scenario is this. I would like to check that a list of logins exist on a group of database instances. My code is pretty repetitive, and looks like…
Andy
  • 399
  • 1
  • 2
  • 10
1
vote
0 answers

Pester test for PowerShell script fails with differing accent characters, how to fix?

I have a problem. I want to test my PowerShell script by Pester. This is my function to test: function Remove-Diacritics { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [String]$string ) …
Franta
  • 11
  • 2
1
vote
1 answer

Pester 5.4 generates an empty Code coverage result file

POV: I'm generating Powershell test code coverage with pester. Problem: The generated Coverage.xml file remains empty. Question What am I doing wrong? Some technicalities: Write-Verbose -Message "Running Pester Tests" $conf =…
JDC
  • 1,569
  • 16
  • 33
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

Pester 5 mocking and beforediscovery

trying to test a function in pester 5.3.1 (latest) and ps7.2.1 function Remove-GraphUser { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [object]$cloudUsers ) process { foreach ($User in…
Kiran Reddy
  • 2,836
  • 2
  • 16
  • 20
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…
1
vote
1 answer

Test Powershell module/script for both Windows (smaller than 5.1) and Core (6 or greater) with AppVeyor CI

I have a PowerShell module on github which has automation on AppVeyor including testing and publishing. One of the recent changes broke the new version with Windows PowerShell. Some groups still run on Windows PowerShell and they informed me about…
Alex Sarafian
  • 634
  • 6
  • 17
1
2