Skip to main content
Version: v6 (preview) 🚧

Configuration

Advanced interface​

Advanced interface uses PesterConfiguration object which contains all options that you can provide to Pester and contains descriptions for all the configuration sections and as well as default values. Here is what you see when you look at the default Debug section of the object:

(New-PesterConfiguration).Debug | Format-List

ShowFullErrors : Show full errors including Pester internal stack. This property is deprecated, and if set to true it will override Output.StackTraceVerbosity to 'Full'. (False, default: False)
WriteDebugMessages : Write Debug messages to screen. (False, default: False)
WriteDebugMessagesFrom : Write Debug messages from a given source, WriteDebugMessages must be set to true for this to work. You can use like wildcards to get messages from multiple sources, as well as * to get
everything. (System.String[], default: System.String[])
ShowNavigationMarkers : Write paths after every block and test, for easy navigation in VSCode. (False, default: False)
ReturnRawResultObject : Returns unfiltered result object, this is for development only. Do not rely on this object for additional properties, non-public properties will be renamed without previous notice. (False,
default: False)

The configuration object can be constructed either using the New-PesterConfiguration command or by casting a hashtable to the PesterConfiguration type. Here are three different ways to the same goal:

# import module before creating the object
Import-Module Pester
# get default from static property
$configuration = New-PesterConfiguration
# adding properties & discover via intellisense
$configuration.Run.Path = 'C:\projects\tst'
$configuration.Filter.Tag = 'Acceptance'
$configuration.Filter.ExcludeTag = 'WindowsOnly'
$configuration.Should.ErrorAction = 'Continue'
$configuration.CodeCoverage.Enabled = $true
# cast whole hashtable to configuration
$configuration = [PesterConfiguration]@{
Run = @{
Path = 'C:\projects\tst'
}
Filter = @{
Tag = 'Acceptance'
ExcludeTag = 'WindowsOnly'
}
Should = @{
ErrorAction = 'Continue'
}
CodeCoverage = @{
Enabled = $true
}
}
# cast from empty hashtable to get default
$configuration = [PesterConfiguration]@{}
$configuration.Run.Path = 'C:\projects\tst'
# cast hashtable to section
$configuration.Filter = @{
Tag = 'Acceptance'
ExcludeTag = 'WindowsOnly'
}
$configuration.Should.ErrorAction = 'Continue'
$configuration.CodeCoverage.Enabled = $true

This configuration object contains all the options that are currently supported and the Simple interface is internally translates to this object internally. It is the source of truth for the defaults and configuration. The Intermediate api will be figured out later, as well as all the other details.

PesterPreference​

There is one more way to provide the configuration object which is $PesterPreference. On Invoke-Pester (in case of interactive execution Invoke-Pester is called inside of the first Describe) the preference is collected and merged with the configuration object if provided. This allows you to configure everything that you would via Invoke-Pester also when you are running interactively (via F5). You can also use this to define the defaults for your session by putting $PesterPreference into your PowerShell profile.

Here is a simple example of enabling Mock logging output while running interactively :

$PesterPreference = New-PesterConfiguration
$PesterPreference.Debug.WriteDebugMessages = $true
$PesterPreference.Debug.WriteDebugMessagesFrom = "Mock"

BeforeAll {
function a { "hello" }
}
Describe "pester preference" {
It "mocks" {
Mock a { "mock" }
a | Should -Be "mock"
}
}
Starting test discovery in 1 files.
Discovering tests in C:\Users\jajares\Desktop\mck.tests.ps1.
Found 1 tests. 44ms
Test discovery finished. 80ms


Running tests from 'C:\Users\jajares\Desktop\mck.tests.ps1'
Describing pester preference
Mock: Setting up mock for a.
Mock: We are in a test. Returning mock table from test scope.
Mock: Resolving command a.
Mock: Searching for command in the caller scope.
Mock: Found the command a in the caller scope.
Mock: Mock does not have a hook yet, creating a new one.
Mock: Defined new hook with bootstrap function PesterMock_b0bde5ee-1b4f-4b8f-b1dd-aef38b3bc13d and aliases a.
Mock: Adding a new default behavior to a.
Mock: Mock bootstrap function a called from block Begin.
Mock: Capturing arguments of the mocked command.
Mock: Mock for a was invoked from block Begin.
Mock: Getting all defined mock behaviors in this and parent scopes for command a.
Mock: We are in a test. Finding all behaviors in this test.
Mock: Found behaviors for 'a' in the test.
Mock: Finding all behaviors in this block and parents.
... shortened Mock does a lot of stuff
Verifiable: False
Mock: We are in a test. Returning mock table from test scope.
Mock: Removing function PesterMock_b0bde5ee-1b4f-4b8f-b1dd-aef38b3bc13d and aliases a for .
[+] mocks 857ms (840ms|16ms)
Tests completed in 1.12s
Tests Passed: 1, Failed: 0, Skipped: 0, Total: 1, NotRun: 0

PesterConfiguration Options​

This section was generated using Pester 6.0.0-alpha5.

Run​

General runtime options for Pester including tests containers to execute.

OptionDescriptionTypeDefault
Run.PathDirectories to be searched for tests, paths directly to test files, or combination of both.string[]@('.')
Run.ExcludePathDirectories or files to be excluded from the run.string[]@()
Run.ScriptBlockScriptBlocks containing tests to be executed.scriptblock[]@()
Run.ContainerContainerInfo objects containing tests to be executed.ContainerInfo[]@()
Run.TestExtensionFilter used to identify test files.string'.Tests.ps1'
Run.ExitExit with non-zero exit code when the test run fails. Exit code is always set to $LASTEXITCODE even when this option is $false. When used together with Throw, throwing an exception is preferred.bool$false
Run.ThrowThrow an exception when test run fails. When used together with Exit, throwing an exception is preferred.bool$false
Run.PassThruReturn result object to the pipeline after finishing the test run.bool$false
Run.SkipRunRuns the discovery phase but skips run. Use it with PassThru to get object populated with all tests.bool$false
Run.SkipRemainingOnFailureSkips remaining tests after failure for selected scope, options are None, Run, Container and Block.string'None'
Run.FailOnNullOrEmptyForEachFails discovery when -ForEach is provided $null or @() in a block or test. Can be overriden for a specific Describe/Context/It using -AllowNullOrEmptyForEach.bool$true

Filter​

Filter options to include/exclude tests and blocks in the targeted containers using tags, name or location. Include by default when no include filters are provided. Exclude filters take precedence.

OptionDescriptionTypeDefault
Filter.TagTags of Describe, Context or It to be run.string[]@()
Filter.ExcludeTagTags of Describe, Context or It to be excluded from the run.string[]@()
Filter.LineFilter by file and scriptblock start line, useful to run parsed tests programmatically to avoid problems with expanded names. Explicit filter that overrides -Skip. Example: 'C:\tests\file1.Tests.ps1:37'string[]@()
Filter.ExcludeLineExclude by file and scriptblock start line, takes precedence over Line.string[]@()
Filter.FullNameFull name of test with -like wildcards, joined by dot. Example: '*.describe Get-Item.test1'string[]@()

CodeCoverage​

Options to enable and configure Pester's code coverage feature.

OptionDescriptionTypeDefault
CodeCoverage.EnabledEnable CodeCoverage.bool$false
CodeCoverage.OutputFormatFormat to use for code coverage report. Possible values: JaCoCo, CoverageGutters, Coberturastring'JaCoCo'
CodeCoverage.OutputPathPath relative to the current directory where code coverage report is saved.string'coverage.xml'
CodeCoverage.OutputEncodingEncoding of the output file.string'UTF8'
CodeCoverage.PathDirectories or files to be used for code coverage, by default the Path(s) from general settings are used, unless overridden here.string[]@()
CodeCoverage.ExcludeTestsExclude tests from code coverage. This uses the TestFilter from general configuration.bool$true
CodeCoverage.RecursePathsWill recurse through directories in the Path option.bool$true
CodeCoverage.CoveragePercentTargetTarget percent of code coverage that you want to achieve, default 75%.decimal75
CodeCoverage.UseBreakpointsWhen false, use Profiler based tracer to do CodeCoverage instead of using breakpoints.bool$false
CodeCoverage.SingleHitBreakpointsRemove breakpoint when it is hit. This increases performance of breakpoint based CodeCoverage.bool$true

TestResult​

Export options to output Pester's testresult to knwon file formats like NUnit and JUnit XML.

OptionDescriptionTypeDefault
TestResult.EnabledEnable TestResult.bool$false
TestResult.OutputFormatFormat to use for test result report. Possible values: NUnitXml, NUnit2.5, NUnit3 or JUnitXmlstring'NUnitXml'
TestResult.OutputPathPath relative to the current directory where test result report is saved.string'testResults.xml'
TestResult.OutputEncodingEncoding of the output file.string'UTF8'
TestResult.TestSuiteNameSet the name assigned to the root 'test-suite' element.string'Pester'

Should​

Options to control the behavior of the Pester's Should assertions.

OptionDescriptionTypeDefault
Should.ErrorActionControls if Should throws on error. Use 'Stop' to throw on error, or 'Continue' to fail at the end of the test.string'Stop'
Should.DisableV5Disables usage of Should -Be assertions, that are replaced by Should-Be in version 6.bool$false

Debug​

Debug configuration for Pester. âš  Use at your own risk!

OptionDescriptionTypeDefault
Debug.ShowFullErrorsShow full errors including Pester internal stack. This property is deprecated, and if set to true it will override Output.StackTraceVerbosity to 'Full'.bool$false
Debug.WriteDebugMessagesWrite Debug messages to screen.bool$false
Debug.WriteDebugMessagesFromWrite Debug messages from a given source, WriteDebugMessages must be set to true for this to work. You can use like wildcards to get messages from multiple sources, as well as * to get everything.string[]@('Discovery', 'Skip', 'Mock', 'CodeCoverage')
Debug.ShowNavigationMarkersWrite paths after every block and test, for easy navigation in VSCode.bool$false
Debug.ReturnRawResultObjectReturns unfiltered result object, this is for development only. Do not rely on this object for additional properties, non-public properties will be renamed without previous notice.bool$false

Output​

Options to customize the console output generated by Pester.

OptionDescriptionTypeDefault
Output.VerbosityThe verbosity of output, options are None, Normal, Detailed and Diagnostic.string'Normal'
Output.StackTraceVerbosityThe verbosity of stacktrace output, options are None, FirstLine, Filtered and Full.string'Filtered'
Output.CIFormatThe CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions.string'Auto'
Output.CILogLevelThe CI log level in build logs, options are Error and Warning.string'Error'
Output.RenderModeThe mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext.string'Auto'

TestDrive​

Options to configure the TestDrive feature.

OptionDescriptionTypeDefault
TestDrive.EnabledEnable TestDrive.bool$true

TestRegistry​

Options to configure the TestRegistry feature. TestRegistry is only available on Windows-systems.

OptionDescriptionTypeDefault
TestRegistry.EnabledEnable TestRegistry.bool$true