Pester assertions should all start with capital letters. This makes code easier to read.
Bad:
it 'Should return something' {
get-targetresource @testParameters | should -be 'something'
}
Good:
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
Pester assertions should always start with the word ‘Should’. This is to ensure the test results read more naturally as well as helping to indentify assertion messages that aren’t making assertions.
Bad:
# This is not an assertive message
It 'When calling Get-TargetResource' {
Get-TargetResource @testParameters | Should -Be 'something'
}
Bad:
# This does not start with 'Should'
It 'Something is returned' {
Get-TargetResource @testParameters | Should -Be 'something'
}
Good:
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
Pester test outer Context
block messages should always start with the word
‘When’. This is to ensure the test results read more naturally as well as helping
to indentify context messages that aren’t defining context.
Bad:
# Context block not using 'When'
Context 'Calling Get-TargetResource with default parameters'
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
}
Bad:
Context 'When calling Get-TargetResource'
# Inner context block not using 'When'
Context 'With default parameters'
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
}
}
Good:
Context 'When Get-TargetResource is called with default parameters'
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
}
Good:
Context 'When Get-TargetResource is called'
Context 'When passing default parameters'
It 'Should return something' {
Get-TargetResource @testParameters | Should -Be 'something'
}
}
}