UITests: app resume from background thanks to Siri

This is a quick post about a new feature added by Apple in Xcode8.3 that let me test an edge case through UITests.

The problem

Let’s consider to have a business logic only applied when the app is resumed from background. And let’s say that if the app is resumed from background then your app navigation changes due to your business logic.

Until XCode8.2 every time a new UITest is executed, the app process is killed and the app is executed from scratch.

Browsing the Apple doc I’ve noticed that they have added the access to Siri through XCUIDevice and the only method exposed by it is:

XCUIDevice.shared().siriService.activate(voiceRecognitionText: "")

This let me to simulate the flow in which the user puts the app in background (using the Home button) and then resumes the app using Siri.