iOS單元測試和UI測試全面解析(23)
發表于:2017-03-31來源:51CTO作者:朱先忠點擊數:
標簽:單元測試iOS
letsessionMock=URLSessionMock(data:data,response:urlResponse,error:nil) At the end of setup(),injectthefakesession into theapp as aproperty of theSUT: controllerUnderTest.defaultSession=sessionMock 【注
let sessionMock = URLSessionMock(data: data, response: urlResponse, error: nil)
At the end of setup(), inject the fake session into the app as a property of the SUT:
controllerUnderTest.defaultSession = sessionMock
【注意】您將直接在您的測試中使用偽造的會話,但是這將向你展示如何注入這種偽造的會話;這樣一來,你進一步的測試可以調用使用視圖控制器defaultSession屬性的SUT方法。
現在,您可以編寫測試來檢查是否調用updateSearchResults(_:)方法能夠解析偽造的數據。為此,請把TestExample()方法替換為以下內容︰
-
原文轉自:http://mobile.51cto.com/iphone-535758.htm