首页 > 解决方案 > 在 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.1Pester 5.1.1

标签: powershellpesterpester-5

解决方案


推荐阅读