I have some problems with notifications testing. I reproduced the case in completely new and clean project and still can't receive my notification in tests.
In viewDidLoad()
method I post my notification like this:
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
NotificationCenter.default.post(name: Notification.Name("Test"), object: nil, userInfo: nil);
}
and in my test I try to catch it:
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}
func testExample() {
expectation(forNotification: Notification.Name("Test"), object: nil) { notification in
return true
}
waitForExpectations(timeout: 10, handler: nil)
}
But it does not work.
I found some info here on Stackoverflow that I should fulfill expectation but my handler is not triggered to do so.
Simple code, simple test but it does not work - So frustrating.
BTW I'm using UITests with Xcode 9.4.1 and have found that with UnitTests all works fine. Possible bug?