有人可以告诉我用 Pester 测试不可为空的字符串参数的最佳方法吗?
ParameterBindingValidationException
当我将一个空字符串传递给我的 PowerShell 模块时,我收到一个。
function Get-MyFunc {
param (
[parameter(Mandatory=$true)]
[string]$stringParameter
)
## rest of function logic here
}
我期待能够在我的测试中做到这一点:
Describe 'When calling Get-MyFunc with empty parameters' {
It 'Should throw an exception' {
Get-MyFunc '' | Should Throw
}
}
或这个:
Describe 'When calling Get-MyFunc with empty parameters' {
It 'Should throw an exception' {
PesterThrow { Get-MyFunc '' } | Should Be $true
}
}