4

I'm currently doing server side development for firebase. I'd like to test that my sendMessage function is working by targeting a test token.

I tried using testToken as a value, but arbitrary values will in fact return an error:

Error: The registration token is not a valid FCM registration token

I've searched all over and found no way to test my code without using a phone connected to the service. Am I just missing something?

Does firebase provide any form of test tokens for doing server side development?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Seph Reed
  • 8,797
  • 11
  • 60
  • 125

2 Answers2

4

If you are working with Android, and don't have a device to test with, you should be able to test against an emulator instance. But you will definitely need to provide FCM a real token that's associated with some device, real or virtual.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    To add to this, from everything I've seen so far, an iOS emulator does not allow for push notification registration. Though I'm still uncertain, this is very likely because it has to go through APNs (Apple Push Notification service), and it's not a real device registered to apple. – Seph Reed May 03 '19 at 19:38
0

This is a very good question, but does some raise further questions.

You want a test token, basically that is mocking, so that will be good for unitary test. But for integrations tests you need to have a real token, so you can test the success case and the error case. So in case of error you can retry or write an entry on the database.

Maybe a better aproach for your test as describe is to mock the method sendMessage or the class containing it. However if you follow this path, please remember, mocking is a double edge sword, you should not mock things dependencies because those are already tested. But mock wrapper components using those dependencies. Off course testing require finese, so maybe mocking one thing aint thar bad.

cutiko
  • 9,887
  • 3
  • 45
  • 59
  • In this case, I'm not yet creating a unit test, but am still developing the system. I'd like some proof that my messages are at least making it to firebase. Then I'll work on making sure they make it from firebase to the app. – Seph Reed May 03 '19 at 19:43