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: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Alias#

{{ Fill Alias Description }}

Type: Object
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Be#

{{ Fill Be Description }}

Type: SwitchParameter
Parameter Sets: Be
Aliases: EQ
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Because#

{{ Fill Because Description }}

Type: Object
Parameter Sets: Be, BeExactly, BeGreaterThan, BeLessOrEqual, BeIn, BeLessThan, BeGreaterOrEqual, BeLike, BeLikeExactly, BeNullOrEmpty, BeOfType, BeTrue, BeFalse, Contain, Exist, FileContentMatch, FileContentMatchExactly, FileContentMatchMultiline, HaveCount, HaveParameter, Match, MatchExactly, Throw, Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeExactly#

{{ Fill BeExactly Description }}

Type: SwitchParameter
Parameter Sets: BeExactly
Aliases: CEQ
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeFalse#

{{ Fill BeFalse Description }}

Type: SwitchParameter
Parameter Sets: BeFalse
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeGreaterOrEqual#

{{ Fill BeGreaterOrEqual Description }}

Type: SwitchParameter
Parameter Sets: BeGreaterOrEqual
Aliases: GE
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeGreaterThan#

{{ Fill BeGreaterThan Description }}

Type: SwitchParameter
Parameter Sets: BeGreaterThan
Aliases: GT
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeIn#

{{ Fill BeIn Description }}

Type: SwitchParameter
Parameter Sets: BeIn
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeLessOrEqual#

{{ Fill BeLessOrEqual Description }}

Type: SwitchParameter
Parameter Sets: BeLessOrEqual
Aliases: LE
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeLessThan#

{{ Fill BeLessThan Description }}

Type: SwitchParameter
Parameter Sets: BeLessThan
Aliases: LT
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeLike#

{{ Fill BeLike Description }}

Type: SwitchParameter
Parameter Sets: BeLike
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeLikeExactly#

{{ Fill BeLikeExactly Description }}

Type: SwitchParameter
Parameter Sets: BeLikeExactly
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeNullOrEmpty#

{{ Fill BeNullOrEmpty Description }}

Type: SwitchParameter
Parameter Sets: BeNullOrEmpty
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeOfType#

{{ Fill BeOfType Description }}

Type: SwitchParameter
Parameter Sets: BeOfType
Aliases: HaveType
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-BeTrue#

{{ Fill BeTrue Description }}

Type: SwitchParameter
Parameter Sets: BeTrue
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-CallerSessionState#

{{ Fill CallerSessionState Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-CommandName#

{{ Fill CommandName Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Contain#

{{ Fill Contain Description }}

Type: SwitchParameter
Parameter Sets: Contain
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DefaultValue#

{{ Fill DefaultValue Description }}

Type: Object
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ErrorId#

{{ Fill ErrorId Description }}

Type: Object
Parameter Sets: Throw
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Exactly#

{{ Fill Exactly Description }}

Type: SwitchParameter
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExceptionType#

{{ Fill ExceptionType Description }}

Type: Object
Parameter Sets: Throw
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExclusiveFilter#

{{ Fill ExclusiveFilter Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Exist#

{{ Fill Exist Description }}

Type: SwitchParameter
Parameter Sets: Exist
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpectedContent#

{{ Fill ExpectedContent Description }}

Type: Object
Parameter Sets: FileContentMatch, FileContentMatchExactly, FileContentMatchMultiline
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpectedMessage#

{{ Fill ExpectedMessage Description }}

Type: Object
Parameter Sets: Throw
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpectedType#

{{ Fill ExpectedType Description }}

Type: Object
Parameter Sets: BeOfType
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ExpectedValue#

{{ Fill ExpectedValue Description }}

Type: Object
Parameter Sets: Be, BeExactly, BeGreaterThan, BeLessOrEqual, BeIn, BeLessThan, BeGreaterOrEqual, BeLike, BeLikeExactly, Contain, HaveCount
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FileContentMatch#

{{ Fill FileContentMatch Description }}

Type: SwitchParameter
Parameter Sets: FileContentMatch
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FileContentMatchExactly#

{{ Fill FileContentMatchExactly Description }}

Type: SwitchParameter
Parameter Sets: FileContentMatchExactly
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FileContentMatchMultiline#

{{ Fill FileContentMatchMultiline Description }}

Type: SwitchParameter
Parameter Sets: FileContentMatchMultiline
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-HasArgumentCompleter#

{{ Fill HasArgumentCompleter Description }}

Type: SwitchParameter
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-HaveCount#

{{ Fill HaveCount Description }}

Type: SwitchParameter
Parameter Sets: HaveCount
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-HaveParameter#

{{ Fill HaveParameter Description }}

Type: SwitchParameter
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Invoke#

{{ Fill Invoke Description }}

Type: SwitchParameter
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-InvokeVerifiable#

{{ Fill InvokeVerifiable Description }}

Type: SwitchParameter
Parameter Sets: InvokeVerifiable
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Mandatory#

{{ Fill Mandatory Description }}

Type: SwitchParameter
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Match#

{{ Fill Match Description }}

Type: SwitchParameter
Parameter Sets: Match
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-MatchExactly#

{{ Fill MatchExactly Description }}

Type: SwitchParameter
Parameter Sets: MatchExactly
Aliases: CMATCH
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ModuleName#

{{ Fill ModuleName Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Not#

{{ Fill Not Description }}

Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ParameterFilter#

{{ Fill ParameterFilter Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ParameterName#

{{ Fill ParameterName Description }}

Type: Object
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PassThru#

{{ Fill PassThru Description }}

Type: SwitchParameter
Parameter Sets: Throw
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RegularExpression#

{{ Fill RegularExpression Description }}

Type: Object
Parameter Sets: Match, MatchExactly
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Scope#

{{ Fill Scope Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Throw#

{{ Fill Throw Description }}

Type: SwitchParameter
Parameter Sets: Throw
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Times#

{{ Fill Times Description }}

Type: Object
Parameter Sets: Invoke
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Type#

{{ Fill Type Description }}

Type: Object
Parameter Sets: HaveParameter
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept 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.