1
votes

We have a suite of CodedUI tests for our Windows Forms application.

We have defined an AssemblyInitialize method in a base class which automatically starts up the application.

Although it is generally not necessary to restart our application for each individual test, I would like to detect when a test fails and restart the application automatically prior to the next test.

Is there any way to detect when a test fails?

I've tried setting up an event handler for Playback.PlaybackError to detect when an exception occurs within a test, but this apparently gets called for all exceptions, not just unhandled exceptions.

We have some expected exceptions within our tests which are handled within the test case, but these end up calling the PlaybackError handler unnecessarily.

1

1 Answers

4
votes

The test outcome can be found from the TestContext.CurrentTestOutcome property which can be accessed in a method with the [TestCleanup] attribute.