Closed theficus closed 9 years ago
Thanks! Honestly I am bit surprised it works like that. I thought It worked like this:
try
{
BeforeEach
It
}
catch
{
Should $_
}
finally
{
AfterEach
}
Will have a look.
You're right. I'm not sure what I was thinking when I originally wrote this code. The Setup / Teardown code is explicitly converting terminating errors into non-terminating (lines 131-143 of Functions/SetupTeardown.ps1), and the call to Invoke-TestCaseSetupBlocks (and similar calls) is not contained in the same Try block as the invocation of the test itself.
Got it working, figuring out the tests for it was bit of a pain. I just need to cleanup the whitespace so the Pester.Tests.ps1 stop complaining. And check if BeforeAll AfterAll follow the same rules.
Fixed by #326.
I do a lot of critical setup operations for my tests in BeforeEach/BeforeAll blocks. What I'm noticing is that if something fails in BeforeEach/BeforeAll that it will continue to run all of the "It" tests.
When an "It" test fails because of a BeforeEach/BeforeAll failure it's typically a real pain to troubleshoot after the fact since that history is not captured in the result output. To work around this I need to further complicate my tests by adding a bunch of assertions in the beginning to make sure my environment is in a correct state for the test to run.
This behavior seems wrong to me. I'm pretty sure MSTest doesn't work this way for comparison's sake.
Before blocks should be considered as critical (or you should be able to mark them as critical). If a Before block fails, a subsequent It should immediately fail since the state cannot be guaranteed.
Repro:
Output: