powershell - 在 Pester 中所有带有变量的测试都失败了
问题描述
我已经开始使用 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
解决方案
推荐阅读
- android - Android Emulator 突然崩溃并显示消息“正在保存状态...”
- c# - 将主题名称注入前端最佳方法
- javascript - 在 ReactJS 生产网站中使用 window.scrollTo() 可以吗?
- selenium - 不存在完全匹配的最新 selenium chrome 驱动程序,该怎么办?
- html - Border-radius css 形成一个椭圆形
- python - Pandas read_sql在同时使用index_col和columns参数时复制列
- laravel - AWS ElastiCache Redis 无法从 Laravel 连接,显示错误:池中没有可用的连接
- php - PHP 查看来自同一用户的不同 $_SESSION
- r - r 中的 ymd() 出错:“所有格式都无法解析。未找到格式。”
- excel - 工作簿无法使用 VBA 打开