Trigger A Method When Test Fails


I'm wondering if it's possible to trigger a method when a test fails an assertion? 

I believe this is possible to do on a test level but is it possible at a higher level? I am using Xunit and I would like a screenshot to be taken of my window, but only when a test fails.


Comment actions Permalink
Official comment

Hello Aaronglennon,

Thank you for contacting us.
Our unit test runner doesn't provide such ability to run any code on an assertion failure.
To run a method in this case, you can change your code to surround the assertion with "try" and then execute the method inside the "catch" block.

Comment actions Permalink

Elena Kurakina. I have since found another solution that works. A try catch is not practical as I have hundreds of tests. 

Comment actions Permalink

Aaronglennon, ok, thank you for the feedback.


Please sign in to leave a comment.