如何快速自动发送 FCM 或 APNS 消息? [英] How do I Quickly Automate Sending FCM or APNS Messages?

查看:36
本文介绍了如何快速自动发送 FCM 或 APNS 消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个后端服务,通过 FCM 或 APNS 向移动应用程序发送推送通知.我想创建一个可以在一分钟内运行并验证服务器可以成功发送通知的自动化测试.请注意,我不一定需要检查通知是否已送达,只需检查 FCM 或 APNS 已成功处理发送消息的请求即可.

I am developing a backend service that sends push notifications to mobile apps via either FCM or APNS. I would like to create an automated test that can run in under a minute and validates that the server can successfully send a notification. Note that I do not necessarily need to check that the notification has been delivered, just that FCM or APNS has successfully processed the request to send the message.

我知道理论上我可以使用 appium 之类的工具自动执行此测试,并使用测试挂钩从应用程序检索注册/设备令牌,但使用 appium 测试后端是否可以发送消息似乎很麻烦.我还尝试使用硬编码的注册令牌,但注册和设备令牌容易轮换,因此测试可能会突然停止通过.还有其他选择吗?

I know that theoretically I could automate this test using a tool like appium and use test hooks to retrieve a registration/device token from the app, but it seems cumbersome to use appium to test if the backend can send a message. I have also tried to use a hard coded registration token, but registration and device tokens are prone to rotate, so the test could suddenly stop passing. Are there any other options?

推荐答案

首先,我会考虑我们想要覆盖的场景.

First of all, I would think about what scenario do we want to cover.

  1. 也许,我们想检查是否在需要时向 FCM 发送了请求.这种情况可能在单元级别上完成,模拟类负责发送推送.
  2. 如果您想专门测试 FCM 调用是否成功,那么您实际上并不需要用户设备的正确 Firebase 令牌.根据文档,如果一切配置正确,并且您使用不正确的令牌(甚至没有)向用户发送消息,您仍将获得 http 代码 200.因此,您可以使用通常的集成测试来调用 Firebase API 并检查成功代码 (200) 和错误字段 (MissingRegistration/InvalidRegistration/NotRegistered),如果你得到了这样一对——你的请求成功了.没有太多需要用正确的用户设备令牌来测试它,因为如果其他一切都正确,结果将是相同的(但实际上传递到手机).Firebase 文档
  3. 如果您仍想使用实际令牌,您可以为您的 QA 创建一个特殊的构建类型,它会在每次应用启动时将他们的 Firebase 令牌发送到您服务器上的一个特殊端点.因此,您将始终在服务器上存储最近的 Firebase 令牌以用于测试目的.当然,该测试可能仍然不稳定,但它是一个很好的起点.
  1. Maybe, we want to check that we sent a request to FCM when it is needed. This case might be done on a unit level with mocked classes responsible for sending a push.
  2. If you want to test specifically success of the FCM call, then you don't actually need a correct Firebase token of the user device. According to docs, if everything is configured correctly and you send a message to a user using incorrect token (or even without it), you will still get http code 200. As a result, you may use usual integration test that will call Firebase API and check the success code (200) and error field (MissingRegistration / InvalidRegistration / NotRegistered), and if you get such a pair - your request was succesfull. There is no much need to test it with a correct user device token, because if everything else is correct, the result will be the same (but actually delivered to a phone). Firebase docs
  3. In case if you still want to use an actual token, you can create a special build type for you QAs, that will send their Firebase token to a special endpoint on your server on each app start. As a result, you will always have a recent Firebase token stored on your server to use for test purposes. Of course, that test may still be flacky but it is a good starting point.

这篇关于如何快速自动发送 FCM 或 APNS 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆