我有一些 Pester 测试在控制台中运行良好,但我想自动运行测试并在任何测试失败时发送消息。我读到选项 -EnableExit 导致 Invoke-Pester 返回失败测试的数量。但每当我使用 -EnableExit 时,无论测试是否失败,powershell 控制台都会关闭。它是 Pester 版本 4.7.3。PS版本5.1。
应该Invoke-Pester -EnableExit关闭外壳吗?
如何获取失败测试的数量?
运行良好:
Invoke-Pester -Script D:\tmp\PowerShell\dummy1.Tests.ps1
关闭 shell 窗口:
Invoke-Pester -Script D:\tmp\PowerShell\dummy1.Tests.ps1 -EnableExit
我希望得到一个整数作为输出,但控制台窗口关闭。
您可以通过执行以下操作来获取失败测试的数量:
(Invoke-Pester -Path D:\tmp\PowerShell\dummy1.Tests.ps1 -PassThru -Show None).FailedCount
Run Code Online (Sandbox Code Playgroud)
如果您想要其他数据(通过/跳过的计数、测试结果等),请将输出传递给变量,然后进一步处理:
$testResults = Invoke-Pester -Path D:\tmp\PowerShell\dummy1.Tests.ps1 -PassThru -Show None
| 归档时间: |
|
| 查看次数: |
1419 次 |
| 最近记录: |