Skip to main content
Version: v5

Should

SYNOPSIS#

Should is a keyword that is used to define an assertion inside an It block.

SYNTAX#

Be#

Should [[-ActualValue] <Object>] [-Be] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [<CommonParameters>]

BeExactly#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeExactly] [<CommonParameters>]

BeGreaterThan#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeGreaterThan] [<CommonParameters>]

BeLessOrEqual#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeLessOrEqual] [<CommonParameters>]

BeIn#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeIn] [<CommonParameters>]

BeLessThan#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeLessThan] [<CommonParameters>]

BeGreaterOrEqual#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeGreaterOrEqual] [<CommonParameters>]

BeLike#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeLike] [<CommonParameters>]

BeLikeExactly#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-BeLikeExactly] [<CommonParameters>]

BeNullOrEmpty#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-BeNullOrEmpty] [<CommonParameters>]

BeOfType#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-BeOfType] [-ExpectedType <Object>] [<CommonParameters>]

BeTrue#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-BeTrue] [<CommonParameters>]

BeFalse#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-BeFalse] [<CommonParameters>]

Contain#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-Contain] [<CommonParameters>]

Exist#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-Exist] [<CommonParameters>]

FileContentMatch#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-FileContentMatch] [-ExpectedContent <Object>] [<CommonParameters>]

FileContentMatchExactly#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-ExpectedContent <Object>] [-FileContentMatchExactly] [<CommonParameters>]

FileContentMatchMultiline#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-ExpectedContent <Object>] [-FileContentMatchMultiline] [<CommonParameters>]

HaveCount#

Should [[-ActualValue] <Object>] [-Not] [-ExpectedValue <Object>] [-Because <Object>] [-HaveCount] [<CommonParameters>]

HaveParameter#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-HaveParameter] [-ParameterName <Object>] [-Type <Object>] [-DefaultValue <Object>] [-Mandatory] [-HasArgumentCompleter] [-Alias <Object>] [<CommonParameters>]

Match#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-Match] [-RegularExpression <Object>] [<CommonParameters>]

MatchExactly#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-RegularExpression <Object>] [-MatchExactly] [<CommonParameters>]

Throw#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-Throw] [-ExpectedMessage <Object>] [-ErrorId <Object>] [-ExceptionType <Object>] [-PassThru] [<CommonParameters>]

InvokeVerifiable#

Should [[-ActualValue] <Object>] [-Not] [-InvokeVerifiable] [<CommonParameters>]

Invoke#

Should [[-ActualValue] <Object>] [-Not] [-Because <Object>] [-Invoke] [-CommandName <Object>] [-Times <Object>] [-ParameterFilter <Object>] [-ExclusiveFilter <Object>] [-ModuleName <Object>] [-Scope <Object>] [-Exactly] [-CallerSessionState <Object>] [<CommonParameters>]

DESCRIPTION#

Should is a keyword that is used to define an assertion inside an It block. Should provides assertion methods to verify assertions e.g. comparing objects. If assertion is not met the test fails and an exception is thrown.

Should can be used more than once in the It block if more than one assertion need to be verified. Each Should keyword needs to be on a separate line. Test will be passed only when all assertion will be met (logical conjuction).

EXAMPLES#

EXAMPLE 1#

Describe "d1" {    BeforeEach { $be = 1 }    It "i1" {        $be = 2    }    AfterEach { Write-Host "AfterEach: $be" }}

EXAMPLE 2#

Describe "d1" {    It "i1" {        $user = Get-User        $user | Should -NotBeNullOrEmpty -ErrorAction Stop        $user |            Should -HaveProperty Name -Value "Jakub" |            Should -HaveProperty Age  -Value 30    }}

EXAMPLE 3#

Describe "d1" {    It "i1" {        Mock Get-Command { }        Get-Command -CommandName abc        Should -Invoke Get-Command -Times 1 -Exactly    }}

EXAMPLE 4#

Describe "d1" {    It "i1" {        Mock Get-Command { }        Get-Command -CommandName abc        Should -Invoke Get-Command -Times 1 -Exactly    }}

EXAMPLE 5#

$true | Should -BeFalse

EXAMPLE 6#

$a | Should -Be 10

EXAMPLE 7#

Should -Invoke Get-Command -Times 1 -Exactly

EXAMPLE 8#

$user | Should -NotBeNullOrEmpty -ErrorAction Stop

EXAMPLE 9#

$planets.Name | Should -Be $Expected

PARAMETERS#

-ActualValue#

The actual value that was obtained in the test which should be verified against a expected value.

Type: ObjectParameter Sets: (All)Aliases:
Required: FalsePosition: 1Default value: NoneAccept pipeline input: True (ByValue)Accept wildcard characters: False

-Alias#

{{ Fill Alias Description }}

Type: ObjectParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Be#

{{ Fill Be Description }}

Type: SwitchParameterParameter Sets: BeAliases: EQ
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Because#

{{ Fill Because Description }}

Type: ObjectParameter Sets: Be, BeExactly, BeGreaterThan, BeLessOrEqual, BeIn, BeLessThan, BeGreaterOrEqual, BeLike, BeLikeExactly, BeNullOrEmpty, BeOfType, BeTrue, BeFalse, Contain, Exist, FileContentMatch, FileContentMatchExactly, FileContentMatchMultiline, HaveCount, HaveParameter, Match, MatchExactly, Throw, InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeExactly#

{{ Fill BeExactly Description }}

Type: SwitchParameterParameter Sets: BeExactlyAliases: CEQ
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeFalse#

{{ Fill BeFalse Description }}

Type: SwitchParameterParameter Sets: BeFalseAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeGreaterOrEqual#

{{ Fill BeGreaterOrEqual Description }}

Type: SwitchParameterParameter Sets: BeGreaterOrEqualAliases: GE
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeGreaterThan#

{{ Fill BeGreaterThan Description }}

Type: SwitchParameterParameter Sets: BeGreaterThanAliases: GT
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeIn#

{{ Fill BeIn Description }}

Type: SwitchParameterParameter Sets: BeInAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeLessOrEqual#

{{ Fill BeLessOrEqual Description }}

Type: SwitchParameterParameter Sets: BeLessOrEqualAliases: LE
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeLessThan#

{{ Fill BeLessThan Description }}

Type: SwitchParameterParameter Sets: BeLessThanAliases: LT
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeLike#

{{ Fill BeLike Description }}

Type: SwitchParameterParameter Sets: BeLikeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeLikeExactly#

{{ Fill BeLikeExactly Description }}

Type: SwitchParameterParameter Sets: BeLikeExactlyAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeNullOrEmpty#

{{ Fill BeNullOrEmpty Description }}

Type: SwitchParameterParameter Sets: BeNullOrEmptyAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeOfType#

{{ Fill BeOfType Description }}

Type: SwitchParameterParameter Sets: BeOfTypeAliases: HaveType
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-BeTrue#

{{ Fill BeTrue Description }}

Type: SwitchParameterParameter Sets: BeTrueAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-CallerSessionState#

{{ Fill CallerSessionState Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-CommandName#

{{ Fill CommandName Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Contain#

{{ Fill Contain Description }}

Type: SwitchParameterParameter Sets: ContainAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-DefaultValue#

{{ Fill DefaultValue Description }}

Type: ObjectParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ErrorId#

{{ Fill ErrorId Description }}

Type: ObjectParameter Sets: ThrowAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Exactly#

{{ Fill Exactly Description }}

Type: SwitchParameterParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExceptionType#

{{ Fill ExceptionType Description }}

Type: ObjectParameter Sets: ThrowAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExclusiveFilter#

{{ Fill ExclusiveFilter Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Exist#

{{ Fill Exist Description }}

Type: SwitchParameterParameter Sets: ExistAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExpectedContent#

{{ Fill ExpectedContent Description }}

Type: ObjectParameter Sets: FileContentMatch, FileContentMatchExactly, FileContentMatchMultilineAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExpectedMessage#

{{ Fill ExpectedMessage Description }}

Type: ObjectParameter Sets: ThrowAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExpectedType#

{{ Fill ExpectedType Description }}

Type: ObjectParameter Sets: BeOfTypeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ExpectedValue#

{{ Fill ExpectedValue Description }}

Type: ObjectParameter Sets: Be, BeExactly, BeGreaterThan, BeLessOrEqual, BeIn, BeLessThan, BeGreaterOrEqual, BeLike, BeLikeExactly, Contain, HaveCountAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-FileContentMatch#

{{ Fill FileContentMatch Description }}

Type: SwitchParameterParameter Sets: FileContentMatchAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-FileContentMatchExactly#

{{ Fill FileContentMatchExactly Description }}

Type: SwitchParameterParameter Sets: FileContentMatchExactlyAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-FileContentMatchMultiline#

{{ Fill FileContentMatchMultiline Description }}

Type: SwitchParameterParameter Sets: FileContentMatchMultilineAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-HasArgumentCompleter#

{{ Fill HasArgumentCompleter Description }}

Type: SwitchParameterParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-HaveCount#

{{ Fill HaveCount Description }}

Type: SwitchParameterParameter Sets: HaveCountAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-HaveParameter#

{{ Fill HaveParameter Description }}

Type: SwitchParameterParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Invoke#

{{ Fill Invoke Description }}

Type: SwitchParameterParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-InvokeVerifiable#

{{ Fill InvokeVerifiable Description }}

Type: SwitchParameterParameter Sets: InvokeVerifiableAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Mandatory#

{{ Fill Mandatory Description }}

Type: SwitchParameterParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Match#

{{ Fill Match Description }}

Type: SwitchParameterParameter Sets: MatchAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-MatchExactly#

{{ Fill MatchExactly Description }}

Type: SwitchParameterParameter Sets: MatchExactlyAliases: CMATCH
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ModuleName#

{{ Fill ModuleName Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Not#

{{ Fill Not Description }}

Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ParameterFilter#

{{ Fill ParameterFilter Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-ParameterName#

{{ Fill ParameterName Description }}

Type: ObjectParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-PassThru#

{{ Fill PassThru Description }}

Type: SwitchParameterParameter Sets: ThrowAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-RegularExpression#

{{ Fill RegularExpression Description }}

Type: ObjectParameter Sets: Match, MatchExactlyAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Scope#

{{ Fill Scope Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Throw#

{{ Fill Throw Description }}

Type: SwitchParameterParameter Sets: ThrowAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Times#

{{ Fill Times Description }}

Type: ObjectParameter Sets: InvokeAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

-Type#

{{ Fill Type Description }}

Type: ObjectParameter Sets: HaveParameterAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False

CommonParameters#

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS#

OUTPUTS#

NOTES#

RELATED LINKS#

https://pester.dev/docs/commands/Should

https://pester.dev/docs/usage/assertions

EDIT THIS PAGE#

This page was auto-generated using the comment based help in Pester 5.2.1. To edit the content of this page, change the corresponding help in the pester/Pester repository. See our contribution guide for more information.