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
3 answers

Is there a way to mock an $? return using Pester?

I'm writing tests for a PowerShell application, using Pester. I have been able to create mocks for most functions, but I haven't been able to mock a function returning the $? variable. I'm currently using it to evaluate the returns from AWS CLI…
Bernardo
  • 103
  • 1
  • 10
1
vote
1 answer

Assertion over each item in collection in Pester

I am doing some infrastructure testing in Pester and there is repeating scenario that I don't know how to approach. Let's say, I want to check whether all required web roles are enabled on IIS. I have a collection of required web roles and for each…
jumbo
  • 4,670
  • 5
  • 39
  • 44
1
vote
1 answer

Unit Testing a Class-based DSC resource with Pester

I am having a problem with unit testing a class-based DSC resource. I am trying to Mock a couple of functions in the class and I get a cast error. PSInvalidCastException: Cannot convert the "bool TestVMExists(string vmPath, string vmName)"…
Carl
  • 2,285
  • 1
  • 16
  • 31
1
vote
0 answers

Unable to do type verification on a runspace

I am using Pester to do some unit testing on a module I am creating and I'm having a bit of trouble with one of my functions that is supposed to return a runspace object. When I create a runspace object and do a .GetType() I see the name listed as…
Mike Garuccio
  • 2,588
  • 1
  • 11
  • 20
1
vote
1 answer

Compare the properties of two PsCustomObjects

I know that I can compare the values of two PowerShell objects: PS> $A = [PsCustomObject]@{"A"=1; "B"=$True; "C"=$False} PS> $B = [PsCustomObject]@{"A"=1; "B"=$False; "C"=$False} PS> Compare-Object $A $B -Property A, B, C A B C…
craig
  • 25,664
  • 27
  • 119
  • 205
1
vote
1 answer

PowerShell module functions cannot access variables in caller's scope

I'm using Pester with Selenium WebDriver. WebDriver is initialized in 'BeforeAll' block within corresponding 'Describe' block and the resulting instance is assigned to $driver variable. Then, in 'Describe' and 'It' block I call my custom functions…
YMM
  • 632
  • 1
  • 10
  • 21
1
vote
1 answer

mock a c# dll function in pester?

I am writing a test for a Powershell module that calls a c# dll function. example : [Namespace]:: SomeMethod($param1, $param2) Any ideas on how I can mock this method in my Pester test?
petercli
  • 629
  • 1
  • 8
  • 27
1
vote
1 answer

Pester PowerShell testing for a sample script is not working as expected

Hi all I have a written a sample script to find whether the given string is Palindrome or not as follows function Palindrome1([string] $param) { [string] $ReversString $StringLength = @() $StringLength = $param.Length while ( $StringLength…
Developer
  • 8,390
  • 41
  • 129
  • 238
1
vote
1 answer

Why Pester does not mock a cmdlet with two parameters?

I'm trying to do some Pester testing, and I get strange error "A positional parameter cannot be found" (for private Python cmdlet), is this a limitation of Pester or something is wrong with my code below? TestModule.psm1 code: #public…
Nmktronas
  • 237
  • 3
  • 12
1
vote
1 answer

Testing a powershell DSC script class with pester - Unable to find type [ClassName]

I am trying to test some custom DSC resources written as a class with the help of pester. However I am struggling to work out how to make the class available to a different file. This is not a pester issue really, I can not do this in powershell…
Alexis Coles
  • 1,227
  • 14
  • 19
1
vote
1 answer

Test non-idempotent web methods with Pester

I'm attempting to test a PowerShell command (Set-PropertyValue) that sets a property value of a SharePoint list item. The function use the Invoke-WebMethod function do to the actual work. My current Set-PropertyValue.Test.ps1 file: # include stuff…
craig
  • 25,664
  • 27
  • 119
  • 205
1
vote
1 answer

Pipeline input to functions

I have the following working code that is used to create an HDInsight cluster: New-AzureHDInsightClusterConfig -ClusterSizeInNodes $ClusterNodes ` -VirtualNetworkId ($VNet.Id) ` …
jamiet
  • 10,501
  • 14
  • 80
  • 159
1
vote
1 answer

Where does Pester's Invoke-Pester reside?

According to this documentation it should be possible to measure code coverage using Pester. PS C:\path\to\codeCoverage> Invoke-Pester .\CoverageTest.Tests.ps1 -CodeCoverage .\CoverageTest.ps1 Invoke-Pester : The term 'Invoke-Pester' is not…
030
  • 10,842
  • 12
  • 78
  • 123
1
vote
1 answer

How to finagle Pester to work with pipelined commands

This PowerShell function identifies files which do not contain a particular string: function GetFilesLackingItem([string]$pattern) { Get-ChildItem | ? { !( Select-String -pattern $pattern -path $_ ) } } I am attempting to write a Pester unit…
Michael Sorens
  • 35,361
  • 26
  • 116
  • 172
1
vote
2 answers

Using 'Pester' (PowerShell Unit-Testing framework) with properties

I am trying to wrap a text fixture around some PowerShell code that extends an object with a property. I get an error that appears to be caused by Pester. I have a contrived example below that displays what I am trying to do. Has anyone succeeded in…
msgisme
  • 193
  • 1
  • 9