Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Coded UI Test: How to Continue Execution After Test Case Fails

5.00/5 (1 vote)
13 Aug 2013CPOL1 min read 17.3K  
How to continue execution after test case fails

Introduction

When we are executing a batch of test cases using ordered test, in some situations, we want to continue the execution even if one of the test cases failed. After execution, we want to see the complete report stating passed and failed test cases. This strategy is good for testers who want to execute test cases when they are not on seat.

1. For Easy Scenarios

orderedtestcaseEditor

  1. Open ordered test case by double clicking on it.
  2. There is a check box “Continue after failure” on the bottom left. Make sure it is checked.
  3. Execute this ordered test. you will notice that test cases do not stop executing even if any test case fails.

2. For Difficult Scenarios

Sometimes, test cases fail due to an expected message box. In that kind of scenarios, subsequent test cases will begin to fail one by one.

For that kind of scenario, the correct strategy is to check if the test case status failed, if yes then move the application under test to a base state and subsequent test cases should start from that base state.

We can achieve this in coded UI test by the use of coded UI test. Following are the steps:

C#
[TestCleanup()]
public void MyTestCleanup()
{
    if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
    //check if the test case is failed
    {
        // write some code here to move your application
        // to a base state , for e.g. restart your application
        // Process.Kill("yourapplication.exe");
        // Playback.Wait(3000);
        //Process.Start("yourapplication.exe");
    }
}
  1. Open your testcase.cs file
  2. Un-comment the testCleanup method
  3. Write the below code in your test cleanup method
  4. Note that testcleanup method executes after each test case

I hope the above scenarios will help test engineers to execute test cases in a much better way.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)