How to make the test clean up method runs only when the test failed?
-
Tuesday, November 01, 2011 5:02 PM
Hi,
I have a test cleanup method for every coded ui test which is running after every test run. How to make the test cleanup runs only when the test failed. Appreciate your help..
Thanks,
Suneetha
All Replies
-
Tuesday, November 01, 2011 9:06 PM
You can put this in your cleanup method:
if (TestContext.CurrentTestOutcome.ToString() == "Failed") { //Do Something }
- Proposed As Answer by Deepak.Singhal [MSFT]Microsoft Employee Wednesday, November 02, 2011 2:26 AM
- Marked As Answer by Shubhra Maji MSFTMicrosoft Employee, Moderator Tuesday, November 08, 2011 10:49 AM
-
Wednesday, November 02, 2011 4:45 PM
Thank you.
-Suneetha.
-
Thursday, November 03, 2011 9:40 PM
Here is the TestCleanup method i used for this
[TestCleanup()] public void MyTestCleanup() { // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463 switch (this.TestContext.CurrentTestOutcome) { case UnitTestOutcome.Failed: { this.TestContext.WriteLine("Browser was closed by the MyTestCleanup() method due to a failure on the test!"); this.UIMap.Action_CloseIE9(); break; } } }
NOTE UnitTestOutCome object has multiple values to check, hence i have it in a c# swtich statement so that i can edit it with ease in the future
- Proposed As Answer by Fabfella Thursday, November 03, 2011 9:40 PM
- Marked As Answer by Shubhra Maji MSFTMicrosoft Employee, Moderator Tuesday, November 08, 2011 10:49 AM

