UI Automation testing on iOS9

During WWDC2015, Apple announced big stuff, but they also released awesome features for developers. One of them was dedicated to UI Testing. Working around UI Automation test, I’ve just discovered last Xcode 7 and how life is going to be easier with their last feature for that.


Before iOS9, we had to use Instruments app with part of javascript framework to record, create and test script to be sure that everything was still working in our app. With last Apple IDE, I discovered the simplest way to create UI automation test, and the best part is this cool feature is available in Xcode.

UI Testing Xcode7

UI Test framework is the perfect mix between Unit Test framework and Instruments Automation. On your Xcode project, you can add a new target, specifying that a UI Test. Once done, your project is already ready to test.

In this new project part, you should find a template test file. That’s what we are going to use to discover this tool. There is a red button at the bottom, it allows us to launch and record taps on the simulator. Record means generate lines of code according to your tap and gesture done on it. Code can be generated in Objective-C and Swift language (no need javascript anymore!).

UI Testing

When your method is ready to be tested, you only need to pick the checkbox for the method like for Unit Test. You can now launch your app on the UI Test target and see how your test is executed.

At the end of your test, you can see time of execution for each line of code and how long the compiler wait for a result. Linked to each row, you can have quick look of the last state of the screen, and that is pretty cool!

UI Testing results

Like Instruments, you are able to get access to a given element from it accessibility label. If a same label has many occurrences, like a UITableViewCell, you can list them a sort it to find the good one.

However, I also can see few weaknesses in that: for automation test, UI Testing can be only deployed on OSX Server and obviously it’s only available for iOS9+. I’m not sure if it’s enough efficient to manage advanced tests when we know that all apps are linked one to each other, with deep linking and other SDK, and I didn’t talk about Bluetooth and native stack yet.

But I’m looking forward testing that this summer on physical device. During this time, here is the video of UI Testing in Xcode, so brilliant and understandable that I hope you’ll watch it.


© 2023 Benoit Pasquier. All Rights Reserved
Author's picture

Benoit Pasquier

Software Engineer 🇫🇷, writing about career development, mobile engineering and self-improvement

ShopBack 💰

Singapore 🇸🇬