Reputation: 502
A certain function in my iOS Swift app will quit the app if the build is deemed to be invalid (out of date etc.).
How do I use XCTest to determine if the app has successfully quit and has returned the simulator to the homescreen?
I've tried the obvious ways like
XCTAssertFalse(XCUIApplication().exists, "app should have quit")
and
XCTAssertFalse(XCUIApplication().enabled, "app should have quit")
if I try and do any operations on XCUIApplication it hangs.
Upvotes: 2
Views: 394
Reputation: 7173
You can register an observer in the NSNotificationCenter
for UIApplicationDidEnterBackgroundNotification
and in your tests, if the build is found to be out of date, make a test exception:
let expectation = expectationWithDescription("myDescription")
waitForExpectationsWithTimeout(10) { error in
}
and in your notification handler:
func someHandler() {
expectation.fulfill()
//unregister the observer
}
That way if the notification is posted, the expectation will be fulfilled, otherwise the test will fail. Be sure to only set up this case if the build is outdated, otherwise it will always fail if the notification isn't posted.
Upvotes: 1