How write unit test for receiving nsnotification asynchronous?

送分小仙女□ 提交于 2019-12-10 13:47:33

问题


I call rest web servic with completion handler and if succeed I send NSNotification.

The problem is how to write unit test to assert that the notification is sent in case of success.

Any help will be appreciated.


回答1:


You can add an expectation for the notification:

expectationForNotification("BlaBlaNotification", object: nil) { (notification) -> Bool in

// call the method that fetches the data
sut.fetchData()  

waitForExpectationsWithTimeout(5, handler: nil)

But personally I would split this is two tests. One for the fetching of the data (tested using a stub) and one for the sending of the notification.



来源:https://stackoverflow.com/questions/34371335/how-write-unit-test-for-receiving-nsnotification-asynchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!