How to make the output in the pipeline appear on the console when running pester tests?

左心房为你撑大大i 提交于 2021-01-28 05:00:21

问题


By default, the output in the pipeline is hidden,But sometimes I really want to know the output at that time.

Of course, I knew I could add additional commands, such as write-host or out-default.

But does Pester itself have a mechanism to make the output display properly?

I checked the help document and didn't find the relevant content, so I came here for help.


回答1:


It is possible to write a custom Should wrapper (proxy) using this technique. The wrapper can write the pipeline objects to the console.

Here is a complete example of such a Should wrapper and how to override Pester's Should.

To apply it to your case, edit the process{} block of the wrapper like this:

process {
    try {
        # Here $_ is the current pipeline object
        Write-Host "Current test case input:`n$( $_ | Out-String )"
        
        # forward it to "process" block of original "Should"
        $steppablePipeline.Process( $_ )
    } catch {
        throw
    }
}


来源:https://stackoverflow.com/questions/65490526/how-to-make-the-output-in-the-pipeline-appear-on-the-console-when-running-pester

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!