简体   繁体   English

Pester 5.4 生成一个空的代码覆盖率结果文件

[英]Pester 5.4 generates an empty Code coverage result file

POV: I'm generating Powershell test code coverage with pester. POV:我正在使用 pester 生成 Powershell 测试代码覆盖率。

Problem: The generated Coverage.xml file remains empty.问题:生成的 Coverage.xml 文件仍然为空。

Question What am I doing wrong?问题我做错了什么?

Some technicalities:一些技术细节:

    Write-Verbose -Message "Running Pester Tests"
    $conf = New-PesterConfiguration
    $conf.Run.Path= ".\Tests\"
    $conf.Run.TestExtension = '.Unit.Test.ps1'
    $conf.Output.CIFormat = "AzureDevops"
    $conf.TestResult.Enabled = $true
    $conf.TestResult.OutputPath = './TestResults/Testresult.xml'
    $conf.CodeCoverage.Enabled = $true
    $conf.CodeCoverage.OutputFormat = 'JaCoCo'
    $conf.CodeCoverage.CoveragePercentTarget = 70
    $conf.CodeCoverage.RecursePaths = $true
    $conf.CodeCoverage.OutputPath="./TestResults/Coverage.xml"
    $conf.CodeCoverage.Path=".\Tests\*.Unit.Test.ps1"
        
    Invoke-Pester -Configuration $conf
> Get-Module Pester | Where-Object {$_.Version -gt '5.0.0'}

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.4.0                 Pester                              {Add-ShouldOperator, AfterAll, AfterEach, Assert-MockCalled…}
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Changing this改变这个

$conf.CodeCoverage.Path="./Tests/*.Unit.Test.ps1"

to

 $conf.CodeCoverage.Path="./Source/**/*.ps1"

made it work.使它工作。


The documentation is really obscure about this: https://pester.dev/docs/commands/New-PesterConfiguration文档对此非常模糊: https://pester.dev/docs/commands/New-PesterConfiguration

Run:跑步:

Path: Directories to be searched for tests, paths directly to test files, or combination of both.路径:要搜索测试的目录、直接指向测试文件的路径或两者的组合。 Default value: @('.')默认值: @('。')

CodeCoverage:代码覆盖率:

Path: Directories or files to be used for code coverage, by default the Path(s) from general settings are used, unless overridden here.路径:用于代码覆盖的目录或文件,默认情况下使用常规设置中的路径,除非在此处被覆盖。
Default value: @()默认值: @()

The general settings say: path to test files.一般设置说:测试文件的路径。 CodeCoverage says: path from general settings is used.. CodeCoverage 说:使用常规设置中的路径..

This made me believe CodeCoverage should point to the test files.这让我相信 CodeCoverage 应该指向测试文件。

Yet their default settings don't even work.然而,他们的默认设置甚至不起作用。

This put me on the wrong track.这让我走错了路。

Thanks to Daniel for putting me on the correct track.感谢丹尼尔让我走上了正确的轨道。


Correction更正

The file is generated, yet the coverage is incorreclty always 0%文件已生成,但覆盖率不正确,始终为 0%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM