【发布时间】:2016-01-20 11:04:08
【问题描述】:
是否可以模拟应用程序 NSBundle 以在 TDD 期间返回可预测的结果?
例如:
我想测试我的应用程序在文件未保存到 NSBundle 时的处理能力:
//Method to test
func getProfileImage() -> UIImage {
if let profileImagePath = getProfilePhotoPath() {
UIImage(contentsOfFile: profileImagePath)
}
return UIImage(named: "defaultProfileImage")
}
private func getProfilePhotoPath() -> String? {
return NSBundle.mainBundle().pathForResource("profileImage", ofType: "png")
}
是否可以模拟 NSBundle.mainBundle() 为 pathForResource 返回 false?
【问题讨论】:
标签: ios swift unit-testing mocking tdd