I'm writing a UI test for my app and am trying to determine if/when a given NSNotification is posted to the default NotificationCenter. I defined a XCTNSNotificationExpectation in my UI test:
let expectation = XCTNSNotificationExpectation(name: notificationName, object: nil, notificationCenter: NotificationCenter.default)
let result = XCTWaiter().wait(for: [expectation], timeout: 10)
I'm posting this notification in my app, but the UI test expectation is not being fulfilled (the result is .timedOut)
My guess is that the NotificationCenter that my app is posting to is not the same NotificationCenter that my UI test is listening to, because the UI test doesn't have visibility into the app's innards.
Q: Are XCTNSNotificationExpectations supposed to work in UI tests? If so, can someone provide an example of what the test code should look like?
Thanks in advance!