Pester is the ubiquitous test and mock framework for PowerShell.
Inconclusive is back!
Should -HaveParameter regression is fixed.
And more:
And also a bit thank you to @fflaten!
Contrary to my tweet, we won't remove support for 3, 4, and 6.2 in Pester 5, the PR was added and then reverted. Will keep that change for Pester 6.
My certificate was renewed, and you will get error on update, because the Issuer changed. And there is no way to get valid certificate from the previous issuer. It is still signed by me, but don't take my word for it, go check the certificate.
Full Changelog: https://github.com/pester/Pester/compare/5.5.0...5.6.0-beta1
Full Changelog: https://github.com/pester/Pester/compare/5.4.1...5.5.0
Full Changelog: https://github.com/pester/Pester/compare/5.4.1...5.5.0-rc1
Full Changelog: https://github.com/pester/Pester/compare/5.4.0...5.4.1
In this release there are many fixes and improvements thanks @fflaten to providing most of them!
Output is now printed with colors in AzureDevOps:
To achieve that, Pester detects if the host supports ANSI codes and uses them to output the string. You can control this by this new option:
[PesterConfiguration]::Default.Output.RenderMode
Default Description Value
------- ----------- -----
Auto The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext. Auto
And optionally switch back to classical ConsoleColor, or a new PlainText mode that outputs just text without any embedded formatting.
Should -HaveParameter
can now ensure that there are multiple aliases set for a parameter.
function f {
param( [Alias('UserName')] $Name )
$Name
}
Get-Command f | Should -HaveParameter Name -Alias 'n', 'UserName'
InvalidResult:
Line |
1 | Get-Command f | Should -HaveParameter Name -Alias 'n', 'UserName'
| Expected command f to have a parameter Name, with aliases 'n' and 'UserName',
| but it didn't have an alias 'n'.
Pester captures the current path in which Invoke-Pester
is invoked, and returns to this path after the execution of the test, even if the tests change it:
PS C:\projects\myModule> Invoke-Pester -Container (
New-PesterContainer -ScriptBlock {
Describe "d" {
It "i" {
Set-Location C:\Windows
}
}
})
This will return back to C:\projects\myModule
after your tests finish running.
Mock, Should -Invoke and InModuleScope are now allowed for manifest modules.
Add Should-example for exception-assertion by @fflaten in https://github.com/pester/Pester/pull/2171
Updates to comment help and examples by @fflaten in https://github.com/pester/Pester/pull/2196
Fix mocks with enum-parameters and ValidateRange by @fflaten in https://github.com/pester/Pester/pull/2191
Don't run Get-CimInstance on Nanoserver by @irishismyname in https://github.com/pester/Pester/pull/2192
Exit invoked testfile after interactive execution by @fflaten in https://github.com/pester/Pester/pull/2218
Add ANSI support for output by @fflaten in https://github.com/pester/Pester/pull/2199
Fix hang in New-TestRegistry when access is denied by @fflaten in https://github.com/pester/Pester/pull/2236
Add support for assigning lists to StringArrayOption by @fflaten in https://github.com/pester/Pester/pull/2232
Throw in Add-ShouldOperator when max number of operators is reached by @fflaten in https://github.com/pester/Pester/pull/2231
Validate Should -Invoke is invoked in specified -Scope blocktype by @fflaten in https://github.com/pester/Pester/pull/2230
Add -Because to Should -Invoke and -InvokeVerifiable by @fflaten in https://github.com/pester/Pester/pull/2229
Fix NRE when assigning null to arrayoption in hashtable by @fflaten in https://github.com/pester/Pester/pull/2219
Fix module installation in PowerShell 3 and 4 by @fflaten in https://github.com/pester/Pester/pull/2214
Add help for dynamic operator parameters by @fflaten in https://github.com/pester/Pester/pull/2170
Fix broken assertions link in help by @fflaten in https://github.com/pester/Pester/pull/2205
Support int and double values when merging decimaloption by @fflaten in https://github.com/pester/Pester/pull/2186
Update ExpandedPath before executing tests and blocks by @fflaten in https://github.com/pester/Pester/pull/2254
Full Changelog: https://github.com/pester/Pester/compare/5.3.3...5.4.0
In this release there are many fixes and improvements thanks @fflaten to providing most of them!
Output is now printed with colors in AzureDevOps:
To achieve that, Pester detects if the host supports ANSI codes and uses them to output the string. You can control this by this new option:
[PesterConfiguration]::Default.Output.RenderMode
Default Description Value
------- ----------- -----
Auto The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext. Auto
And optionally switch back to classical ConsoleColor, or a new PlainText mode that outputs just text without any embedded formatting.
Should -HaveParameter
can now ensure that there are multiple aliases set for a parameter.
function f {
param( [Alias('UserName')] $Name )
$Name
}
Get-Command f | Should -HaveParameter Name -Alias 'n', 'UserName'
InvalidResult:
Line |
1 | Get-Command f | Should -HaveParameter Name -Alias 'n', 'UserName'
| Expected command f to have a parameter Name, with aliases 'n' and 'UserName',
| but it didn't have an alias 'n'.
Pester captures the current path in which Invoke-Pester
is invoked, and returns to this path after the execution of the test, even if the tests change it:
PS C:\projects\myModule> Invoke-Pester -Container (
New-PesterContainer -ScriptBlock {
Describe "d" {
It "i" {
Set-Location C:\Windows
}
}
})
This will return back to C:\projects\myModule
after your tests finish running.
Mock, Should -Invoke and InModuleScope are now allowed for manifest modules.
Add Should-example for exception-assertion by @fflaten in https://github.com/pester/Pester/pull/2171
Updates to comment help and examples by @fflaten in https://github.com/pester/Pester/pull/2196
Fix mocks with enum-parameters and ValidateRange by @fflaten in https://github.com/pester/Pester/pull/2191
Don't run Get-CimInstance on Nanoserver by @irishismyname in https://github.com/pester/Pester/pull/2192
Exit invoked testfile after interactive execution by @fflaten in https://github.com/pester/Pester/pull/2218
Add ANSI support for output by @fflaten in https://github.com/pester/Pester/pull/2199
Fix hang in New-TestRegistry when access is denied by @fflaten in https://github.com/pester/Pester/pull/2236
Add support for assigning lists to StringArrayOption by @fflaten in https://github.com/pester/Pester/pull/2232
Throw in Add-ShouldOperator when max number of operators is reached by @fflaten in https://github.com/pester/Pester/pull/2231
Validate Should -Invoke is invoked in specified -Scope blocktype by @fflaten in https://github.com/pester/Pester/pull/2230
Add -Because to Should -Invoke and -InvokeVerifiable by @fflaten in https://github.com/pester/Pester/pull/2229
Fix NRE when assigning null to arrayoption in hashtable by @fflaten in https://github.com/pester/Pester/pull/2219
Fix module installation in PowerShell 3 and 4 by @fflaten in https://github.com/pester/Pester/pull/2214
Add help for dynamic operator parameters by @fflaten in https://github.com/pester/Pester/pull/2170
Fix broken assertions link in help by @fflaten in https://github.com/pester/Pester/pull/2205
Support int and double values when merging decimaloption by @fflaten in https://github.com/pester/Pester/pull/2186
Update ExpandedPath before executing tests and blocks by @fflaten in https://github.com/pester/Pester/pull/2254
Full Changelog: https://github.com/pester/Pester/compare/5.3.3...5.4.0-rc1
fix ForEach casing in Context #2111
Fix duplicate key exception in Should-InvokeInternal debug logging #2130
Adds default parameter set to New-MockObject #2160
Update help for New-Fixture #2097
Add discord-link and cleanup README #2102
Update devcontainer to NET 6.0 SDK and Powershell 7.2 #2116
Use newer images in our pipeline #2141
Thanks @ArmaanMcleod, @fflaten and @johlju for all your contributions and support!
New way of measuring code coverage was added. It uses the core of Profiler to measure code coverage, instead of using breakpoints. This makes code coverage much much faster for bigger solutions. To enable it use UseBreakpoints
option, and set it to $false
:
$configuration.CodeCoverage.UseBreakpoints = $false
The option is marked as experimental, but from our tests it looks like the new approach is as accurate as the breakpoint based approach. The new approach does not yet work on PS3.
New option for controlling the verbosity of failed tests was added:
$configurationOutput.StackTraceVerbosity
With the folloing levels:
None - All Stack trace is hidden FirstLine - First line of stack trace is shown Filtered - Filtered lines that belong to Pester. This is default. Full - All stack trace is shown
More info and more screenshots are in the PR.
Output for discovery and filter was reduced in the Detailed and Diagnostic output, by moving discovery messages per file into the Diagnostic output, and hiding the Filter messages from the default Diagnostic output. All messages are still available via custom filter in $configuration.Debug.WriteDebugMessagesFrom
.
More info and more screenshots are in the PR.
Pester automatically detects if it is running in AzureDevOps or GitHub Actions and augments the output to report errors correctly.
The default is to autodetect CI but it can be disabled by:
$configuration.Output.CIFormat = 'None'
More info and more screenshots are in the PR.
New-MockObject
can now override properties and methods on the created object. It counts the number of executions of a method and collects parameters provided to methods. It can also take an object as input and add properties and methods to it.
# Create an empty process object
$o = New-Object -TypeName 'System.Diagnostics.Process'
# Override Kill method to just return "killed"
$mockObject = New-MockObject -InputObject $o -Methods @{ Kill = { param($entireProcessTree) "killed" } }
$mockObject.Kill()
$mockObject.Kill($true)
# Inspect the history of invocations in `_<methodName>`
$mockObject._kill
# Output:
# Call Arguments
# ---- ---------
# 1 {}
# 2 {True}
More examples are in the tests: https://github.com/pester/Pester/blob/main/tst/functions/New-MockObject.Tests.ps1 Real life-examples here: https://youtu.be/8GWqkGvV3H4?t=2517
A new option was added, that allows skipping the rest of the execution when any test fails. It can skip tests in the current block and all child blocks, as well as skip all remaining tests in the file, or in the whole run.
$configuration.Run.SkipRemainingOnFailure = 'Block'
The following scopes are supported:
Block - Skip all remaining tests in current bloc k(including child blocks and tests) after a failed test. Container - Skip all remainng tests in the container (file or scriptblock) after a failed test. Run - Skip all tests across all containers in a run after a failed test. None - Default, keep original behaviour.
We used Skipped test result to skip those tests, but there was a lively discussion about how this should be achieved. Share your feedback if you have any.
More info and more screenshots are in the PR.
Mocks pick up all variables from your tests. When your variable names are the same as parameter names of a mocked command this can lead to unexpected results in ParameterFilter. We added a new message in the Diagnostic log that warns you that a variable is in conflict with a parameter name.
It 'filter should not pass due to test-variable' {
$SamAccountName = 'abc'
# Mock parameter filter below does not pass because SamAccountName is 'def'
Get-Stuff -SamAccountName 'def'
# Mock parameter filter below does "incorrectly" passes because SamAccountName is not specified here
# but is set to 'abc' by the variable above
Get-Stuff
# This assertion fails because there was 1 call, and not 0 calls, because we had naming conflict betwween
# parameters and our variables.
Should -Invoke Get-Stuff -Times 0 -Exactly -ParameterFilter { $SamAccountName -eq 'abc' }
}
TestDrive internals were improved to save the location of test drive directory, instead of querying it every time. This greatly improved performance of any run.
When you don't need TestDrive
or TestRegistry
, you can disable both TestDrive and TestRegistry entirely, to get more performance gains:
$configuration.TestDrive.Enabled = $false
$configuration.TestRegistry.Enabled = $false
Disabling TestRegistry is also useful on restricted systems when access to Windows Registry is disabled by group policy.
See full log here