Testing FCM Notifications? Like a pro!

Chetan Sachdeva
Fueled Engineering
Published in
3 min readNov 6, 2017

Firebase has a very extensive documentation for testing FCM notifications in Android and iOS. There are times when the developers or the QA team is stymied if the feature API isn’t implemented on the backend. This post is intended to help test FCM notifications easily. This can be done using:

  1. Firebase Notification Composer
  2. HTTP protocol with Postman

There are 2 types of notifications, generic notifications (handled by Firebase SDK implicitly) and custom notifications (received in onMessageReceived of the FirebaseMessagingService which the developer can customize based on the requirement).

Firebase SDK will identify notifications as foreground or background based on notification and data nodes sent in the payload.

Let’s take an example notification with title as “Collapsing A” and body as “First Notification”.

1. Firebase Notification Composer

The console field labels will map to the following nodes in the payload sent.

Go to Firebase console > Notifications or follow this link. Click NEW MESSAGE and compose a message as follows:

For Generic notifications

Just fill the first few fields and hit SEND MESSAGE. This notification is handled by Firebase SDK implicitly and triggered only when app is in background. Make sure to select Target user if… as app package name for all devices or Single Device to send it to a particular device.

For Custom in-app and background notifications

Fill in the Advanced options with Custom data and hit SEND MESSAGE. These notifications are handled explicitly by developers. Here, collapse_key will override the actual collapse_key of the parent payload.

Disclaimer: You can’t send custom background notification using this as it will always send a notification node in the payload.

2. HTTP protocol with Postman

Go to Firebase Console > Project Settings > Cloud Messaging and copy the Legacy server key.

  • You can push a generic notification (with notification payload) or a custom notification (with notification and data payload) and hit Send.
  • Note that custom background notification will only trigger if there is only data (without notification) node in the payload. Hence, you’d need to move the body and title to data node.

Use registration_ids instead of to node if you want to send notification to multiple devices with corresponding firebase_instance_id's.

Happy Testing!

There! We tested our FCM notifications. If this post made you happy, you can sing the Pharrell Williams song and clap along 👏🏻😊

--

--