Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Quickly Automate Sending FCM or APNS Messages?

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.

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?

like image 626
Scott Kausler Avatar asked Oct 30 '18 03:10

Scott Kausler


Video Answer


2 Answers

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

  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.
like image 99
Gaket Avatar answered Sep 24 '22 00:09

Gaket


Appium is automation framework for black-box testing, so in your case, it allows to check if the notification pops up on a device. And that's it.

Appium has no access to your application code, you can send adb commands via it, but basically, no way to play with tokens until you expose it to the UI layer of your app.

Moreover, Appium is not supported by Firebase.

I suggest looking into Espresso, where you write tests with direct access to your application code.

like image 25
dmle Avatar answered Sep 25 '22 00:09

dmle