Skip to main content
Version: v5

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:

[PesterConfiguration]::Default.Debug | Format-List

ShowFullErrors : Show full errors including Pester internal stack. (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. (*, default: *)
ShowNavigationMarkers : Write paths after every block and test, for easy navigation in VSCode. (False, default: False)
New in Pester 5.2.0!

New-PesterConfiguration is now available and the recommended way to create the PesterConfiguration-object. It has the added benefit of auto-loading the Pester-module if needed and up-to-date help of available options in the configuration object.

The configuration object can be constructed either via the Default static property or by casting a hashtable to it. You can also cast a hashtable to any of its sections. Here are three different ways to the same goal:

# import module before creating the object
Import-Module Pester
# get default from static property
$configuration = [PesterConfiguration]::Default
# 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 = [PesterConfiguration]::Default
$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 5.6.1.

Run​

Run configuration.

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'

Filter​

Filter configuration

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. 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​

CodeCoverage configuration.

OptionDescriptionTypeDefault
CodeCoverage.EnabledEnable CodeCoverage.bool$false
CodeCoverage.OutputFormatFormat to use for code coverage report. Possible values: JaCoCo, CoverageGuttersstring'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.UseBreakpointsEXPERIMENTAL: When false, use Profiler based tracer to do CodeCoverage instead of using breakpoints.bool$true
CodeCoverage.SingleHitBreakpointsRemove breakpoint when it is hit.bool$true

TestResult​

TestResult configuration.

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​

Should configuration.

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'

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​

Output configuration

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​

TestDrive configuration.

OptionDescriptionTypeDefault
TestDrive.EnabledEnable TestDrive.bool$true

TestRegistry​

TestRegistry configuration.

OptionDescriptionTypeDefault
TestRegistry.EnabledEnable TestRegistry.bool$true