我用完成处理程序调用 rest web 服务,如果成功我发送 NSNotification。
问题是如何编写单元测试来断言成功时发送通知。
我们将不胜感激。
最佳答案
您可以为通知添加期望:
expectationForNotification("BlaBlaNotification", object: nil) { (notification) -> Bool in
// call the method that fetches the data
sut.fetchData()
waitForExpectationsWithTimeout(5, handler: nil)
但我个人认为这是两个测试。一种用于获取数据(使用 stub 测试),另一种用于发送通知。
关于ios - 如何编写异步接收nsnotification的单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34371335/