我有一个Pester脚本,它正在为我的API运行一些冒烟测试。当我运行Invoke-Pester时,我得到了Logo,测试运行良好。然而,在日志的末尾,我得到了Tests Passed: 0, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0,当我试图作为一个NUnitXML输出时,那里也没有结果。
命令:
Invoke-Pester -Script @{Path = 'Path\testscript.ps1'; Arguments = '200', 'application/json; charset=utf-8'} -OutputFormat NUnitXml -OutputFile ".\TestsResults.xml"脚本:
param(
[string]$HttpCode,
[string]$ContentType
)
Import-Module Pester -Force
Describe 'API Smoke Tests' {
Context "Direct Endpoint Smoke Test: $Uri" {
It 'HTTP Code Should be equal to "200"' {
$HttpCode | Should -Be 200
}
It 'Content Type Should be equal to "application/json; charset=utf-8"' {
$ContentType | Should -Be "application/json; charset=utf-8"
}
}
}控制台日志:
____ __
/ __ \___ _____/ /____ _____
/ /_/ / _ \/ ___/ __/ _ \/ ___/
/ ____/ __(__ ) /_/ __/ /
/_/ \___/____/\__/\___/_/
Pester v4.9.0
Executing all tests in 'Path\testscript.ps1'
Executing script Path\testscript.ps1
Describing API Smoke Tests
Context Direct Endpoint Smoke Test:
[+] HTTP Code Should be equal to "200" 10ms
[+] Content Type Should be equal to "application/json; charset=utf-8" 6ms
Tests completed in 1.59s
Tests Passed: 0, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0 发布于 2019-11-25 21:13:05
我可以用以下脚本重现您的问题:
go.ps1
Import-Module -Name ".\Pester-4.9.0\Pester.psd1"
Invoke-Pester -Script @{
Path = ".\script.ps1"
Arguments = @( "200", "application/json; charset=utf-8" )
} `
-OutputFormat "NUnitXml" `
-OutputFile ".\Results.xml"script.ps1
param
(
[string] $HttpCode,
[string] $ContentType
)
Import-Module -Name .\Pester-4.9.0\Pester.psd1 -Force
Describe 'API Smoke Tests' {
Context "Direct Endpoint Smoke Test: $Uri" {
It 'HTTP Code Should be equal to "200"' {
$HttpCode | Should -Be 200
}
It 'Content Type Should be equal to "application/json; charset=utf-8"' {
$ContentType | Should -Be "application/json; charset=utf-8"
}
}
}然后:
C:\> powershell .\go.ps1
____ __
/ __ \___ _____/ /____ _____
/ /_/ / _ \/ ___/ __/ _ \/ ___/
/ ____/ __(__ ) /_/ __/ /
/_/ \___/____/\__/\___/_/
Pester v4.9.0
Executing all tests in '.\script.ps1'
Executing script .\script.ps1
Describing API Smoke Tests
Context Direct Endpoint Smoke Test:
[+] HTTP Code Should be equal to "200" 114ms
[+] Content Type Should be equal to "application/json; charset=utf-8" 7ms
Tests completed in 0.99s
Tests Passed: 0, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0注- Tests Passed: 0
问题是,您从Pester中已经运行的脚本中导入Pester。答案是从Import-Module中删除script.ps1,然后得到:
C:\> powershell .\go.ps1
____ __
/ __ \___ _____/ /____ _____
/ /_/ / _ \/ ___/ __/ _ \/ ___/
/ ____/ __(__ ) /_/ __/ /
/_/ \___/____/\__/\___/_/
Pester v4.9.0
Executing all tests in '.\script.ps1'
Executing script .\script.ps1
Describing API Smoke Tests
Context Direct Endpoint Smoke Test:
[+] HTTP Code Should be equal to "200" 106ms
[+] Content Type Should be equal to "application/json; charset=utf-8" 5ms
Tests completed in 623ms
Tests Passed: 2, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0注- Tests Passed: 2
我认为您所看到的症状是Pester如何积累测试结果的一部分--它将它们存储在一个全局状态中,因此,可能发生的事情类似于测试实际上正在script.ps1 Pester模块中运行(这就是您看到的测试输出),但是最终的测试摘要来自于运行了零测试的go.ps1 Pester模块。
不过,这只是推测--最终,不要从你的Pester测试中导入Pester,一切都应该正常工作.
https://stackoverflow.com/questions/59029653
复制相似问题