我已经开始使用 Pester 为我的脚本编写测试用例PowerShell
,但不幸的是,我什至在简单的测试中都失败了。对于任何测试,如果It
块中有变量,即使它应该通过,测试也会失败。
下面是一个简化的代码:
Describe 'Basic Pester Tests' {
It 'A test that should be true' {
$true | Should -Be $true
}
}
Describe 'should exist with variables test' {
$someFile = 'C:\Scripts\EnableFlash.ps1'
It "$someFile should exist" {
$someFile | Should -Exist
}
}
Describe 'should exist without variable test' {
It "'C:\Scripts\EnableFlash.ps1' should exist" {
'C:\Scripts\EnableFlash.ps1' | Should -Exist
}
}
Describe 'compare for addition' {
$a = 10; $b = 20
It "test for variables" {
$($a+$b) | Should -Be 30
}
}
在上面的代码中,测试should exist with variables test
失败而测试should exist without variable test
成功。
我正在使用PowerShell 5.1
和Pester 5.1.1