如何使用带有四个标准参数的 pester v5 配置或容器?

How can I use pester v5 configuration or container with four standard arguments?

我正在尝试调用一个 pester 脚本,从 pester V4.6.0 移动到 V5.3.1

我在调用 pester 时使用的 V4 参数是:

-supplying custom parameters
-OutputFormat NUnitXML
-OutputFile $xmlpath
-EnableExit

但是,对于 v5,我似乎需要使用配置或容器来调用 Pester,这两者都不能完全满足我在 V4 中使用的参数。限制似乎是:

Invoke-Pester -Configuration $pesterConfig $pesterConfig 不喜欢我在其中指定自定义数据参数的地方,例如: 数据 = @{dataFactoryName = $dataFactoryName;}

Invoke-Pester -Container $container -ErrorAction Stop -输出详细 -CI $container 不喜欢我指定的地方: -OutputFormat NUnitXML -输出文件 $xmlpath -启用退出

我怎样才能更有效地使用容器或配置,以允许我指定以下 4 件事:

-supplying custom parameters
-OutputFormat NUnitXML
-OutputFile $xmlpath
-EnableExit

一个解决方法是使用配置,它满足我的 4 个参数中的 3 个,并将自定义数据传递给文件或环境变量,并在调用的 ps 脚本中读取它。不过可能不太理想。

找到了一种同时使用配置和容器的方法:

        $container = New-PesterContainer -Path "..." -Data @{
            customParamA= "value"; 
            customParamB= "value"; 
        }

        $pesterConfig = [PesterConfiguration]@{
            Run = @{
                Exit = $true
                Container = $container
            }
            Output = @{
                Verbosity = 'Detailed'
            }
            TestResult = @{
                Enabled      = $true
                OutputFormat = "NUnitXml"
                OutputPath   = $xmlpath
            }
            Should = @{
                ErrorAction = 'Stop'
            }
        }

        Invoke-Pester -Configuration $pesterConfig