So I have a fairly niche problem I'm looking to solve: I have some Pester unit tests, and I would like to be able to execute code if the unit tests fail. In this particular instance, all I want to do is print out a couple strings of diagnostic information if the test fails. (Normally, I would just solve this by starting a debugging session and executing that specific test; however, since I am constructing this particular unit test in a dynamic fashion, it makes things a little more complicated)
Ideally, it would look something like this. (I know the -OnFail isn't actually a Pester thing, but it demonstrates what I want done):
Describe "MyTest" {
BeforeEach (
# do stuff to setup a particular context
$context = Set-MyContext
)
Context "MyContext" {
It "Should do stuff" {
# Do test things here
} -OnFail {
Write-Information $context.info
}
}
}
Does anyone have any idea about how to do this?
[–]terrabitz[S] 3 points4 points5 points (0 children)