【发布时间】:2020-08-20 20:05:41
【问题描述】:
我想对一些UNUserNotificationCenterDelegate 方法进行单元测试,尤其是userNotificationCenter(_, willPresent:, withCompletionHandler:)
为此,我必须创建一个UNNotification 的实例,但这实际上是不可能的,因为它只有一个initWithCoder 初始化程序。怎么办?
这是我想测试的示例:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler(.sound)
}
【问题讨论】:
标签: swift xcode unit-testing push-notification unusernotificationcenter