Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
Pester is the ubiquitous test and mock framework for PowerShell.
PowerShell Batchfile
Branch: master
Clone or download
KirkMunro and nohwnd Add header to Pester output that shows the version (#1343)
Add header to Pester output that shows ascii art and the version of the module.
Latest commit f4bab35 Aug 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add note about using Fix to automatically close related issues Jan 5, 2019
.vscode Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
Dependencies Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
Examples Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
Functions Add header to Pester output that shows the version (#1343) Aug 8, 2019
Snippets Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
bin remove rouge link that appeared out of nowhere Feb 20, 2018
en-US Add header to Pester output that shows the version (#1343) Aug 8, 2019
images Update images May 2, 2019
lib/Gherkin Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
vendor Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
.appveyor.yml Print full errors when internal flag is specified (#1232) Feb 1, 2019
.gitattributes Update Pester to work on PowerShell Core at Windows, Linux, macOS (#925) Nov 11, 2017
.gitignore Update images May 2, 2019
.travis.yml Print full errors when internal flag is specified (#1232) Feb 1, 2019
CHANGELOG.md Bump to 4.8.1 May 11, 2019
LICENSE Added Apache version 2.0 license Aug 23, 2011
Pester.Tests.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
Pester.nuspec fix deploy Feb 20, 2018
Pester.psd1 Bump to 4.8.1 May 11, 2019
Pester.psm1 Add detection for Constant or ReadOnly variable names (#1292) Jun 17, 2019
README.md Fixed typo in README.md (#1254) Feb 22, 2019
VERIFICATION.txt Support all natural languages which Gherkin provides (#1166) Jan 5, 2019
azure-pipelines.yml Print full errors when internal flag is specified (#1232) Feb 1, 2019
buildNugetPackage.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
buildPSGalleryPackage.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
chocolateyInstall.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
cleanUpBeforeBuild.ps1 Rename the folder doc to images (#1183) Dec 28, 2018
getNugetExe.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
nunit_schema_2.5.xsd Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
publishPSGalleryPackage.ps1 Force publishing psgallery package May 11, 2019
release.ps1 Support all natural languages which Gherkin provides (#1166) Jan 5, 2019
report.dtd Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
signModule.ps1 Fix .Length mispelling in duplicate certificate thumbprint check in s… Mar 10, 2019
testRelease.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019
updateGherkinLanguageFile.ps1 Fix formatting to use automatic Struostrup style in VSCode (#1203) Jan 9, 2019

README.md

Pester

📦🔐 Pester is now signed. -SkipPublisherCheck should no longer be used to install from PowerShell Gallery on Windows 10.

👩👨 We are looking for contributors! All issues labeled help wanted are up for grabs. They further split up into good first issue that are issues I hope are easy to solve. Bad first issue where I expect the implementation to be problematic or needs to be proposed and discussed beforehand. And the rest which is somewhere in the middle. If you decide to pick up an issue please comment in the issue thread so others don't waste their time working on the same issue as you. There is also contributor's guide that will hopefully help you.

Pester is the ubiquitous test and mock framework for PowerShell.

# your function
function Get-Planet ([string]$Name='*')
{
  $planets = @(
    @{ Name = 'Mercury' }
    @{ Name = 'Venus'   }
    @{ Name = 'Earth'   }
    @{ Name = 'Mars'    }
    @{ Name = 'Jupiter' }
    @{ Name = 'Saturn'  }
    @{ Name = 'Uranus'  }
    @{ Name = 'Neptune' }
  ) | foreach { [PSCustomObject]$_ }

  $planets | where { $_.Name -like $Name }
}

# Pester tests
Describe 'Get-Planet' {
  It "Given no parameters, it lists all 8 planets" {
    $allPlanets = Get-Planet
    $allPlanets.Count | Should -Be 8
  }

  Context "Filtering by Name" {
    It "Given valid -Name '<Filter>', it returns '<Expected>'" -TestCases @(
      @{ Filter = 'Earth'; Expected = 'Earth' }
      @{ Filter = 'ne*'  ; Expected = 'Neptune' }
      @{ Filter = 'ur*'  ; Expected = 'Uranus' }
      @{ Filter = 'm*'   ; Expected = 'Mercury', 'Mars' }
    ) {
      param ($Filter, $Expected)

      $planets = Get-Planet -Name $Filter
      $planets.Name | Should -Be $Expected
    }

    It "Given invalid parameter -Name 'Alpha Centauri', it returns `$null" {
      $planets = Get-Planet -Name 'Alpha Centauri'
      $planets | Should -Be $null
    }
  }
}

This code example lies a tiny bit, find it annotated and production ready here.

Learn more about the usage and syntax on our wiki.

Installation

Pester is compatible with Windows PowerShell 2.x - 5.x on Windows 10, 8, 7, Vista and even 2003. Since version 4.0.9 Pester is compatible also with PowerShell Core 6.x on Windows, Linux, macOS but with some limitations.

Pester comes pre-installed with Windows 10, but we recommend updating, by running this PowerShell command as administrator:

Install-Module -Name Pester -Force

Not running Windows 10 or facing problems? See the full installation and update guide.

Features

Test runner

Pester runs your tests and prints a nicely formatted output to the screen.

test run output

Command line output is not the only output option, Pester also integrates with Visual Studio Code, Visual Studio, and any tool that can consume nUnit XML output.

Assertions

Pester comes with a suite of assertions that cover a lot of common use cases. Pester assertions range from very versatile, like Should -Be, to specialized like Should -Exists. Here is how you ensure that a file exists:

Describe 'Notepad' {
    It 'Exists in Windows folder' {
        'C:\Windows\notepad.exe' | Should -Exist
    }
}

Learn more about assertion on our wiki.

Mocking

Pester has mocking built-in. Using mocks you can easily replace functions with empty implementation to avoid changing the real environment.

function Remove-Cache {
    Remove-Item "$env:TEMP\cache.txt"
}

Describe 'Remove-Cache' {
    It 'Removes cached results from temp\cache.text' {
        Mock -CommandName Remove-Item -MockWith {}

        Remove-Cache

        Assert-MockCalled -CommandName Remove-Item -Times 1 -Exactly
    }
}

Learn more about Mocking here.

Code coverage

Pester can measure how much of your code is covered by tests and export it to JaCoCo format that is easily understood by build servers.

JaCoCo code coverage report

Learn more about code coverage here.

Build server integration

Pester integrates nicely with TFS, AppVeyor, TeamCity, Jenkins and other CI servers.

Testing your scripts, and all pull requests on AppVeyor is extremely simple. Just commit this appveyor.yml file to your repository, and select your repository on the AppVeyor website:

version: 1.0.{build}
image:
  - Visual Studio 2017
  - Ubuntu
install:
  - ps: Install-Module Pester -Force -Scope CurrentUser
build: off
test_script:
  - ps: Invoke-Pester -EnableExit

See it in action here! If you do not need to test your scripts against PowerShell Core, just simply remove the entire line mentioning Ubuntu.

Pester itself is built on the community build server and Travis CI, and distributed mainly via PowerShell gallery.

PowerShell 2 & 3

PowerShell 4, 5 & Core on Windows build

Linux & MacOS build

latest version

downloads

Further reading

Do you like what you see? Learn how to use Pester with our wiki guide, and continue with some of the other resources.

Got questions?

Got questions or you just want to get in touch? Use our issues page or one of these channels:

Pester Twitter

Pester on StackOverflow

Testing channel on Powershell Slack

Pester Gitter

Pester on PowerShell.org

You can’t perform that action at this time.