Trigger A Method When Test Fails

Answered

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.

 

3 comments
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. 

1
Comment actions Permalink

Aaronglennon, ok, thank you for the feedback.

0

Please sign in to leave a comment.