336 questions
0
votes
1
answer
135
views
Why Pester requires InModuleScope for unit tests to run successfully? Why mocks won't work as expected with dot sourcing?
I'm exploring Pester for unit testing my PowerShell scripts, and I'm running into a mocking issue.
I dot-source my functions like this:
. "$PSScriptRoot\tz-docker.functions.ps1"
But my ...
0
votes
1
answer
59
views
Unit test a function without coupling tightly to implementation when the function side effects are not visible
I have a PowerShell function that updates IIS configuration. I want to write Pester unit tests for the function. However, the function doesn't return a value and doesn't set a value that's ...
4
votes
1
answer
124
views
Create an instance in PowerShell of a .NET type without a constructor
I have a PowerShell script for setting up a website in IIS. It includes the following function:
function Set-IisWebsiteBinding (
[Parameter(Mandatory = $true)]
[string]$SiteName,
[...
-1
votes
2
answers
1k
views
How to use temporary files and folder in GitHub Actions with PowerShell Pester
I am finishing setting up a PowerShell Module and I have set a series of 5 Pester tests that pass locally but not on GitHub actions. I wonder that may be due to restrictions on the creation of files ...
1
vote
1
answer
192
views
Trouble mocking Powershell function with Pester that takes a Pipeline parameter
I am receiving the following error when trying get this pester test to work for a function that receives a pipeline parameter.
"An error occured running Pester: The input object cannot be bound ...
1
vote
1
answer
98
views
Problem using PowerShell Class contained in module when running Pester test for a different module that utilizes the Class module
I wrote the following MyTypes module with a simple Class:
class Person {
[string] $Name
Person([string] $name ) {
$this.Name = $name
}
}
Then I defined the following MyModule ...
1
vote
1
answer
36
views
Cannot get Pester Test to use Mock for "New-Object OfficeOpenXml.ExcelPackage"
I have been unable to get the mock for New-Object to work.
Below is the function and the test inline.
Import-Module ImportExcel -Force
function Clear-ExcelWorksheet {
[CmdletBinding()]
param (...
2
votes
2
answers
112
views
Mocking a pipeline function that returns a single object from the end block
In Pester I need to mock a pipeline function that creates a hashtable in the begin block, updates it in the process block, and returns it in the end block.
I thought it would be a simple case of ...
0
votes
0
answers
142
views
Failure in VS Code Pester extension when refreshing the tests
I am using VS Code for my PowerShell development. I have version 5.1 of PowerShell and version 1.95.3 of VS Code. I have the Pester extension installed in VS Code (version v2023.7.7). Until recently, ...
0
votes
1
answer
50
views
Test Invocations of `Set-NetFirewallProfile` having the `-Profile` argument using Pester mocking
I am working on some unit tests for a powershell module and I am at a loss for how to test if the Set-NetfirewallProfile was called with the correct parameters. It seems that I am not correctly ...
0
votes
1
answer
191
views
How to mock New-AzStorageContext in Pester
I would like to mock New-AzStorageContext to return a value that can be used as the DestContext parameter of the function Start-AzStorageBlobCopy.
I have tried New-MockObject of Microsoft.WindowsAzure....
0
votes
0
answers
367
views
In Azure DevOps, link manual test cases with automated test scripts using PowerShell Pester Framework and CI/CD Pipeline
I have written automated tests using PowerShell Pester Framework. We have Azure DevOps for project management and I have the same TCs written in Test Plans -> Test Suites. We also are running the ...
0
votes
1
answer
112
views
Pester 'It' or 'Context' array iteration
Pester 5.6.1
Powershell 7.4.5
Here's the deal. I have data that I am loading in the BeforeDiscovery. I can reference all the variables within at the Run stage...no problem there. Even the string ...
0
votes
1
answer
127
views
The mock in my pester test keeps calling Connect-AzAccount
I dont understand why I cant test my Read-VaultSecret.
in my file appsettings.psm1, i have a this function
function Read-VaultSecret($vault, $secretId)
{
try {
return Read-SecureString((...
0
votes
1
answer
74
views
How to test function that mocks Get-ChildItem w/ -File parameter?
This Pester test:
BeforeAll {
function Get-HtmlFileDetail {
param (
[string[]]$Path = 'E:\Domains',
[string[]]$Include = 'Alive*.html'
)
return Get-...