iOS单元测试和UI测试全面解析(29)
发表于:2017-03-31来源:51CTO作者:朱先忠点击数:
标签:单元测试iOS
在BullsEyeMockTests类中声明SUT对象和模拟对象: varcontrollerUnderTest:ViewController! varmockUserDefaults:MockUserDefaults! 在方法setup()中,创建SUT对象和模拟对象,然后把此
在BullsEyeMockTests类中声明SUT对象和模拟对象:
-
var controllerUnderTest: ViewController!
-
var mockUserDefaults: MockUserDefaults!
在方法setup()中,创建SUT对象和模拟对象,然后把此模拟对象注入为该SUT的一个属性:
-
controllerUnderTest = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! ViewController!
-
mockUserDefaults = MockUserDefaults(suiteName: "testing")!
-
controllerUnderTest.defaults = mockUserDefaults
原文转自:http://mobile.51cto.com/iphone-535758.htm