Questions tagged [pester-5]
30 questions
1
vote
0 answers
Pester's XML report contains only the file name, not full path
I'm new to Pester, I was testing the things locally then i got this problem. When i generate the XML report in pester it contains this line
but when i generate the HTML file…

Sunil P S
- 11
- 2
1
vote
1 answer
All tests with variables are failing in Pester
I have started using Pester to write test cases for my PowerShell scripts, but unfortunately, I am failing in even simple tests. For any test, if there is a variable in the It block the test fails even though it should pass.
Below is a simplified…

Pramod
- 391
- 5
- 21
0
votes
1 answer
Pester doesn't reflect changes in a script
I'm using Pester version:5.3.3
and not quite sure if I do it properly. I have only one file containing the whole logic: Function.Tests.ps1.
BeforeAll{
import-module .\Function.Tests.ps1 -Force
Remove-Item -Path "$PSScriptRoot\testresults.xml"…

Purclot
- 483
- 7
- 22
0
votes
1 answer
Invoke-Pester v5 doesn't run my TestCases
I am learning Pester and am trying to create a default template for my PowerShell modules.
I created this Pester ps1 file:
BeforeAll {
[System.IO.DirectoryInfo]$ModuleRoot = (Get-Item -Path $PSScriptRoot).Parent
[System.String]$ModulePath =…

Mark
- 339
- 2
- 4
- 11
0
votes
1 answer
Pester - Execute the same set of tests for different modules
I currently have a PowerShell module that extends another module. Basically, my new module re-implements one Function to provide custom behavior for a specific customer:
Base Module - Implements 12 Functions and Exports 12 Functions.
Customer Module…
0
votes
1 answer
How do I check if a specific exception type has been thrown in Pester 5.4.0?
I want to write a test in PowerShell with Pester 5.4.0 to check whether a specific exception type has been thrown inside a script block. It should be fairly easy, but I am somehow not doing it right. Following along the Pester v5 documentation for…

dan-kli
- 568
- 2
- 13
0
votes
1 answer
Pester 5 - Access Multiple Variables in Nested Loop
I am converting Pester tests from V4 to V5 and in line with the best practices, moving the loops from foreach() to Describe -ForEach{}. The tests are a standard set that checks if each function has comment based help and this requires multiple…

Ninja
- 356
- 1
- 3
- 12
0
votes
0 answers
Commands not recognized when running Pester from VSCode
I'm trying to run Pester to test PowerShell scripts, but I can't get VSCode to execute the tests.
My code
Implementation
I have the following code on a file ConvertTo-Nanosecond.ps1:
function ConvertTo-Nanosecond {
[CmdletBinding()]
param (
…

Roäc
- 149
- 19
0
votes
1 answer
Providing test cases to Pester V5 test
I'm trying to write a pester test (v5) to see if various services are running on remote computers. This is what I have, which works:
$Hashtable = @(
@{ ComputerName = "computer1"; ServiceName = "serviceA" }
@{ ComputerName =…

Andy
- 399
- 1
- 2
- 10
0
votes
1 answer
Pester 5 code coverage in Azure DevOps - File does not exist (any more)
Ever since Pester 5 a Pester configuration is recommended to generate test and code coverage output. The old school Pester 4 method still works, but we wanted to get rid of the legacy warning.
Since we started to use Pester Configuration, Azure…

Peter the Automator
- 796
- 6
- 16
0
votes
0 answers
Mocking Auth Token function in Pester
I have written a PowerShell function that generates an auth token in azure using REST API call. I am using the tenant id, Service principal client id and client secret as input param to generate this token. The SP client id and client secret are…

Zoltaire
- 21
- 3
0
votes
1 answer
get-childitem either subfolder or a "rbac.jsonc" file
I want to check if all folders contains either a subfolder or an rbac.jsonc file.
I want to iterate through a list of folder $topMgFolderPath being the root folder.
I want to go all the way down the tree in the folders
I am are looking to trigger a…

Nadia Hansen
- 697
- 2
- 6
- 16
0
votes
1 answer
How can I verify the value of a parameter being passed into a mocked function using Pester
I have a function written in PowerShell and I am trying to test that function using Pester v-5. I have included the function under test and the Pester test case in the code samples below.
I am trying to verify that the parameter $FileName being…

gerard
- 835
- 11
- 27
0
votes
1 answer
How to define an 'It' test for a nested function in Pester 5?
Given a PowerShell script (.ps1) with functions and nested functions. The function 'Inner' should not be moved to the outer scope and thus not be exported. How can one define an 'It' test for the 'Inner' function (hopefully without modifying the…

jamacoe
- 519
- 4
- 16
0
votes
1 answer
Pester Mock imported module
I'm using version pester version 5.1.0
I've created a simple test.psm1
function testScript { write-host 'hello' }
I've create a pester file let's call it test-tests.ps1
Describe "test" {
Context "test call" {
Import-Module…

user7786267
- 137
- 12