Andy
Andy

Reputation: 1423

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

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.

Upvotes: 2

Views: 653

Answers (1)

zett42
zett42

Reputation: 27776

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
    }
}

Upvotes: 2

Related Questions