DevPrep

All topics › Software testing

UI tests with XCUITest: accessibilityIdentifier, Page Object and stability

Middle PRO

The gist

XCUITest launches the app in a separate process and drives it from the outside, like a user, through the accessibility tree. The test runner cannot see the app's code: you cannot call a ViewModel method or pass a stub through init, and @testable import does not help here. All communication is arguments and environment variables at launch plus elements on screen. Hence three rules of stability: replace the backend with launch flags, find elements by accessibilityIdentifier, wait for events instead of sleeping.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store