【发布时间】:2015-10-11 19:46:22
【问题描述】:
我正在编写一个包装UILocalNotifiations 的框架,并且正在为其编写单元测试。它实际上更像是一个功能测试,但无论如何。
所以,我要写的测试是:
func testAlertManagerCanRegisterLocalNotifications() {
let manager = Manager()
manager.alerts = DummyAlerts
let app = UIApplication.sharedApplication()
let scheduledNotifs = app.scheduledLocalNotifications ?? []
XCTAssertEqual(scheduledNotifs.count, manager.alerts.count)
}
鉴于当 alerts 属性发生突变时管理器同步调度 UILocalNotifications,此测试应该通过.. 但它没有。
这里的根本原因是测试没有必要的权限来安排通知,我不知道我应该如何允许测试应用程序获得这些权限?毕竟,没有涉及 UI。
问题:
是否可以强制测试应用拥有必要的UIUserNotification 权限?
【问题讨论】:
-
当然,一种解决方案是模拟
UIApplication对象,但试图找到更好的方法。
标签: ios unit-testing uilocalnotification xctest uiapplication