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

Pester: Use variables in -ForEach data driven tests with rich content

I write a module used for powershell-wrapping a commandline tool. For my tests I had some variables defined in BeforeAll. Those vars should help in feeding the command with desired params and check them against the expected result, f.i. BeforeAll { …
Usul
  • 11
  • 4
1
vote
1 answer

How do I successfully run Pester Unit tests locally on a cloned GitHub repo?

I would like to run all Pester Unit tests locally for a project before pushing my changes back up to GitHub and initializing a Pull Request. So far I've cloned a project, xFailOverCluster, and installed Pester and all dependent modules (found using…
Dennis
  • 871
  • 9
  • 29
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
vote
0 answers

Pester 5 test no longer working with Start-Job

This was working before Pester 5.3.0 but now it seems broken and I do not know why it has stopped working. The idea of this tests is to check to see if counters have been removed, this is part of a larger installation and uninstallation. But the…
M Thompson
  • 25
  • 2
1
vote
1 answer

How to setup a Pester mock with arguments from a function

I have a PowerShell function that unfortunately has several dependencies, so when testing I need to setup several different mocks. As I have several tests with different scenarios and some but not all share similar setup activities, there ends up…
bryanbcook
  • 16,210
  • 2
  • 40
  • 69
1
vote
1 answer

Should -Throw Method in PowerShell

I am trying to run some test in PowerShell that will check if the version in SolutionInfo.cs file is correctly formatted, is it missing or is it okay. With my tests I am trying to cover those scenarios. One of them for checking the file, when the…
Bakula33
  • 65
  • 4
1
vote
2 answers

Why can I not test for ParameterBindingValidationException in Pester?

Given a function that has validation for a parameter: function Test-Validation { [CmdletBinding()] param ( [Parameter()] [ValidateScript({ # Add some validation that can throw. if (-not (Test-Path…
Ash
  • 3,030
  • 3
  • 15
  • 33
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
3 answers

Output debug information from pester test

I'm writing a system in C# that has lots of features to test. One feature is a set of PowerShell custom cmdlets for managing my system. I'm using pester (v5) to test my cmdlets and will have a lot of test cases for the many scenarios that I want to…
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
1
vote
2 answers

Assert array in ParameterFilter for Pester Assert-MockCalled

We are trying to assert a call with specific parameter which is an array and it's returning false in Assert-MockCalled, for all other parameters which are not array it's working (string types). Here is my example: function NewZip ($Name) { …
DAG
  • 2,460
  • 5
  • 33
  • 61
1
vote
1 answer

Use existing json file to test with Pester and TestDrive

I have a json file which is manipulated during an automation process and I have created a unit test for it which works just fine, but I'm accessing the file system and this is for me not the way to go. Then I found out about Pester TestDrive, but I…
DAG
  • 2,460
  • 5
  • 33
  • 61
1
vote
1 answer

How to exclude Paths in the Pester configuration?

We have a directory structure of modules like the following: C:\Program Files\WindowsPowerShell\Modules\Toolbox.CustomModule1 C:\Program Files\WindowsPowerShell\Modules\Toolbox.CustomModule2 C:\Program…
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
1
vote
1 answer

Is there a way I can create an either OR assertion using Pester test framework?

For example if I wanted to assert the value should be Value1 or Value2 (either is acceptable): It 'Value must match Value1 or Value2' { $params.value | Should -be "Value1" || "Value2" }` This is invalid syntax - is there a way to do…
1
vote
0 answers

Use of PipelineVariable fails in Pester test

I have the following declarations: function Get-Datastore { [CmdletBinding()] param ($Name, $Id, $Server, [Parameter(ValueFromPipeline = $true)]$Location) } function Get-ScsiLun { [CmdletBinding()] param ($Server, [Parameter(ValueFromPipeline =…
mhu
  • 17,720
  • 10
  • 62
  • 93