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

Unable to execute "custom script extension" on Azure VM using azure CLI from linux sub system

I am working on developing post-deployment Pester validation script for my project. I need to push pester scripts into the VM as custom script extension using Azure CLI. Following is the command I executed: az vm extension set --resource-group…
Melbin K
  • 55
  • 1
  • 2
  • 6
1
vote
1 answer

Template Validation Error - Error: Code=InvalidTemplate; Message=Deployment template validation failed:

I am having a bit of trouble deploying the template below: azuredeploy.json file One of the error message that has thrown: 'The template resource '[concat('nsg-create',copyIndex())]' at line '344' and column '9' is invalid. The api-version…
1
vote
1 answer

Mock with ParameterFilter Not Being Called (Pester)

I have a string array, $ServerNames, with two elements: 'ServerName1' and 'ServerName2'. I then have a corresponding MOCK: Mock 'Get-ADComputer' { $Server1; write-host 'test'} Mock 'Get-ADComputer' { $foo } -ParameterFilter { $Identity -eq…
Adam
  • 3,891
  • 3
  • 19
  • 42
1
vote
1 answer

Issue Mocking in Nested Modules

1. Provide a general summary of the issue in the Title above 2. Describe Your Environment Pester version : 4.3.1 /usr/local/share/powershell/Modules/Pester/4.3.1/Pester.psm1 PowerShell version : 6.0.1 OS version : Unix 16.7.0.0 3.…
1
vote
1 answer

How to use global variables in Quamotion Pester tests

I'm using Quamotion and Pester to test my mobile app. Right now, I find myself having to repeat a lot of parameters (such as usernames and passwords) which I use in my tests. Is there any way to use global variables in Quamotion/Pester tests?
1
vote
1 answer

Mock Get-ADUser with and without ParameterFilter

I'm pretty new to Pester so please bear with me. We're trying to make tests for a very large script that does some active directory queries and validates data. I've simplified it a bit to the following example: Dummy.ps1 Param ( [String]$OU, …
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
1
vote
1 answer

PowerShell Module cannot be loaded when running Pester test in Visual Studio

I have created a PowerShell test script, Common.tests.ps1, using Pester against some functions in a PowerShell script, Common.ps1, in the same directory. There is a TestInitializer.ps1 script, also in the same directory, which uses the…
1
vote
1 answer

Pester reset test data

This is about scope of test data in pester. I am testing a function Add-HashTableIfNotPresent which checks for the existence of a key in a hashtable, if it doesn't exist it adds it otherwise it returns the value linked to that key. I have 2 It…
ssloan
  • 2,226
  • 4
  • 26
  • 40
1
vote
1 answer

PowerShell path resolves differently depending on when it's used

I'm working on a PowerShell module and the path resolution in one of my tests is acting really weirdly. The current folder structure looks like this: ISPS/ ├── ISPS/ │ ├── Private/ │ ├── Public/ │ │ ├── Add-ICDCrawler.ps1 │ │ ├──…
Brekkjern
  • 31
  • 5
1
vote
0 answers

PESTER - can i use it for powershell workflows?

Friends, I am automating some infra related stuffs using powershell and converting that to workflows and running in SMA (Service Management Automation). Lets say if I have to automate some linux and windows machine storage addition, they I create 1…
Adarsha Murthy
  • 145
  • 3
  • 13
1
vote
0 answers

Test PowerShell AMSI with Pester

I'm writing a Pester test to verify the configuration of Windows computers. One of the tests I need is to verify whether PowerShell AMSI is working or not. There is an AMSI test string that can be used to verify the function. I created the following…
vrdse
  • 2,899
  • 10
  • 20
1
vote
2 answers

Mock New-AzureRmDnsRecordConfig return value of type Microsoft.Azure.Commands.Dns.DnsRecordBase[]

I'm trying to write a unit test for a script that uses New-AzureRmDnsRecordSet. The DnsRecords parameter on New-AzureRmDnsRecordSet validates that I pass in a type of Microsoft.Azure.Commands.Dns.DnsRecordBase[] which is the return value of…
Nick H.
  • 1,616
  • 14
  • 20
1
vote
1 answer

How do i redirect output to the Pester xml file?

I would like to know how to add additional output to the Pester test XML file using PowerShell commands such as Out-Host or Write-Debug. I wish to do this so that I can observe the output on the appveyor tests page. As you can see in the above…
Jfm Meyers
  • 123
  • 1
  • 12
1
vote
1 answer

Pester unit testing function with Mandatory=True

I'm learning slowly using the wonderful Pester unit testing for Powershell for a while now. I'm kind of stuck around the usage of checking if my function can run "if not supplied any mandatory input into a function." which is giving me a red light…
Peter M Taylor
  • 183
  • 1
  • 9
  • 17
1
vote
1 answer

Visual Studio doesn't apply Powershell module changes on Pester unit test execution

I have created a "Powershell Module Project" within Visual Studio 2015 and wrote some functions for the module. When I make changes to the .psm1 file and try to unit test these changes with the Pester framework (.test.ps1 file) the new changes are…