Skip to content

Pester Task

Khoi Ky edited this page Dec 1, 2021 · 5 revisions

Overview

The Pester task runs tests using Pester 5. You pass a hashtable of parameters to the Configuration property that gets casted into a Pester-Configuration. Pester-Configuration contains parameters such as Run.Path, Run.ExcludePath, TestResults.Enabled. You can also pass a hashtable of parameters to the Container property that gets casted into a Pester-Container. The Pester-Container can either be a container or a script block, either of which can be ran with or without data.

Test reports are saved to the output directory in NUnit XML format. The report files are named pester+RANDOM_STRING.xml, where RANDOM_STRING is a random strings of characters.

Properties

  • AsJob: by default, the task runs Pester in Whiskey's private scope. Otherwise, tests run in a background job/process. If you don't want to run in Whiskey's private scope, set this to true.
  • Configuration: a hashtable of parameters that contains variables such as Run.Path, Run.ExcludePath, TestResults.Enabled, etc... This hashtable is then converted to a Pester-Configuration.
  • Container: a hashtable of parameters that contains either a container or a script block, either of which can be with or without data. This hashtable is then converted to a Pester-Container.

Examples

Example 1

Build:
- Pester:
    Configuration: @{ Run = @{ Path = 'Test\*.ps1'; }; }

Demonstrates how to run Pester tests using Pester 5. In this case, all the tests in files that match the wildcard Test\*.ps1 are run.

Example 2

Build:
- Pester:
    Configuration: @{ Run = @{ Path = 'Test\*.ps1'; ExcludePath = '*\\*Pester*.ps1'; }; }

Demonstrates how to use the Pester Configuration's ExcludePath property to exclude tests from running. In this example, all tests in the Tests directory that end in ".Tests.ps1" except files whose base names contain "Pester" will be run.

Example 3

Build:
- Pester:
    Configuration: @{ Run = @{Path = 'Test\*.ps1'; }; TestResult = @{ Enabled = $true; }; }

Demonstrates how to use the Pester Configuration's TestResult property to produce test results for all the tests in files that match the wildcard Test\*.ps1.

Clone this wiki locally