Lesson 32

Introduction to User Interface Testing

User Interface Testing (UI Testing) is a new feature in Xcode 7 that allows you to write code that can launch an instance of your application, interact with UI elements of the application programmatically, and validate the state and properties of these elements.

A related feature, called UI recording, has been introduced in Xcode 7. When UI recording is enabled, you can launch the app and interact with it as you normally would. XCode records your interaction with the app and builds a user interface test that can perform the same sequence of interactions for you.

UI Testing is built upon XCTest, which is Xcode's testing framework. XCTest is used by both user interface tests as well as traditional unit tests. Unit tests are covered in Lesson 34.

Adding Support for UI Testing to Your Project

Adding support for UI testing involves making a few changes to an Xcode project. For starters a new build target must be added that will be used to run the user interface tests. A suitable unit testing framework will also need to be linked with the project.

If you are creating a new project in Xcode, adding support for unit tests is a simple matter of ensuring the Include UI Tests check box is selected in the project options dialog box (see Figure 32.1).

Screenshot of Choose options for your new project dialog box with the option Include UI Tests checked and encircled.

Figure 32.1

When you do this, you will notice a few changes:

  • A new group has been ...

Get Swift iOS 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.