Ordering Tests in Android UIAutomator Testing

UIAutomator does not normally tests in a specific sequence. This is actually good behavior because your tests in your testing code SHOULD be sequence invariant.

It should not matter what order your tests should run in. If all of your tests are sequence specific, it makes it very difficult to parallelize test in the future and speaks of brittle code.

However in the real world there are often business or code dependencies which force us to order tests. To order tests add the @FixMethodOrder and specify the sorting order. We usually just use name ascending and then name or tests in alphabetical order.

  • t01_checkPreconditions
  • t02_emailNotUpdated

Code Example
The following example will then run in alphabetical sort order:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SmokeTest extends AutomationBaseTest {
    @Test
    public void t01_checkPreconditions() {
        # ...
    }

    @Test
    public void t02_emailNotUpdated() throws InterruptedException {
        # ...
    }
# ...
}

George Lee

A full stack engineer who has coded on front end, back end, and mobile and embedded system. Have worked on large scale systems at eBay and agile environments at startups. Specialties: Python, PHP, Objective C, Java, Perl, SQL, Javascript, IOS, Android, Amazon EC2, Linux and Windows.

Leave a Reply

Your email address will not be published. Required fields are marked *