Skip to Main Content
Learning Swift, 3rd Edition
book

Learning Swift, 3rd Edition

by Jonathon Manning, Paris Buttfield-Addison, Tim Nugent
March 2018
Beginner content levelBeginner
378 pages
8h 45m
English
O'Reilly Media, Inc.
Content preview from Learning Swift, 3rd Edition

Chapter 18. UI Tests

We spoke about unit tests back in “Testing the SelfieStore”, but there is another type of testing Xcode can perform. UI tests are a way to run tests on the UI itself. Up to this point, any time we’ve wanted to test something in our UI, such as toggling the states of the settings switches or testing the UI flow for our custom capture view controller, we have had to do so manually. The problem with this is that it obviously doesn’t scale very effectively and can get very boring very quickly for the developer. UI tests are an answer to this: essentially, they give you access to a virtual hand you can script, giving it orders and expectations for it to fulfill. It’s like having your own army of testers you can make do all the tapping and swiping about for you.

Warning

Throughout this chapter we will be making some assumptions about the permissions and setup of Selfiegram. Normally you would not do this and instead would provide setup code to ensure everything is ready for the tests, but as we are interested in showing off how to write UI tests and not general testing methodology we are skipping some of this. In your own apps, make sure you do perform your test setup correctly!

UI Testing Classes

There are three main types we interact with when doing UI testing:

XCUIApplication

A proxy object for the app being tested (in our case, Selfiegram).

XCUIElement

A single UI element we can interact with and query. This can be almost any type, including buttons.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning To Program With Swift

Learning To Program With Swift

T. Rogers

Publisher Resources

ISBN: 9781491987568Errata Page