【发布时间】:2017-11-16 07:41:37
【问题描述】:
我们有一些应用程序需要定期检查推送通知。我们可以通过 Xcode UI 测试检查推送通知吗?
【问题讨论】:
-
我对我的回答做了一些修改,请看一下
标签: push-notification xctest xcode-ui-testing
我们有一些应用程序需要定期检查推送通知。我们可以通过 Xcode UI 测试检查推送通知吗?
【问题讨论】:
标签: push-notification xctest xcode-ui-testing
免责声明:我没有这样做...
您无法生成令牌...所以我猜答案是否定的!可以做的是使用存根数据模拟您的 notificationManager。
使用您测试的存根数据:
否则,如果您纯粹是为了测试应用程序在收到通知时是否抛出callback,那么您正在测试操作系统,这是错误的。你应该只测试你自己的代码。
通过测试你的 notificationManager 我大致的意思是:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NotificationManager.shared.handle(userInfo)
}
你的 NotificationManager 类
func handleAPNSMessage(_ message:[AnyHashable: Any]) {
if let aps = message["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if let message = alert["message"] as? NSString {
//Do stuff
}
} else if let alert = aps["alert"] as? NSString {
//Do stuff
}
}
}
源自here
现在你要做的是,你使用一个看起来与服务器发送给你的 JSON 对象相同的 JSON 对象来模拟调用 handleAPNSMessage,
如果您想发疯并真正复制远程通知,那么您可以使用自己的存根数据并创建本地通知...并查看应用程序是否按预期工作...
编辑:
确保您看到How can I test Apple Push Notification Service without an iPhone?
【讨论】: