There’s often no discernable, consistent pattern that dictates the execution order of automated tests (Coded UI in this example, but the same applies to Unit Tests). Some argue that it may be a good thing that there isn’t an inherent pattern for the execution of CodedUI tests (and unit tests, for that matter), as a seemingly more random pattern can uncover test dependencies which reduce the overall effective coverage of tests. And I agree with that to an extent, but there are always cases in which control over execution order is needed.
An easy way to accomplish test order is to use an Ordered Test. This will provide you explicit control over the execution order of your tests.
For this example, I have a Coded UI Test class called CodedUITest1 (for more on Coded UI Tests, see the Anatomy of a Coded UI Test). In it, I have two CodedUI Test methods:
I want to order them such that they execute like:
1. Add a new Ordered Test. Go to Test->New Test, and select Ordered Test.
2. The ordered test will open. I can move the available tests from the left list into my ordered test list on the right. I can then move the tests up/down to create the desired order.
It’s not shown in this screenshot, but there is a checkbox to allow the ordered test to continue upon a failure.
3. Save the ordered test. I can now see the ordered test in my Test View window.
4. When ready, I select to run my ordered test. It will appear in the Test Results window as a single test.
When finished, I can double-click on the test result to see that both tests did actually run, their individual results, and their order.
It’s a surprisingly easy yet elegant solution. I can put pretty much any automated test into an ordered test (except for load tests). If you have a lot of tests, coupling the use of ordered tests with other test lists can really help visually organize your test project.
Steve, I appreciated your blog about "Ordering Method Execution of a Coded UI Test". But I need to do the same thing from a build definition and a remote execution. Could you please tell me how to "Order" the sequence of my test methods in a build definition file? Thank you. Vance Bradford email@example.com