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

查看:124
本文介绍了如何快速自动发送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天全站免登陆