'how to mock firebase_messaging in flutter?

Hello im trying to mock firebase messaging to get token but when i try to test i get some error,can someone help me to solve this error. This error occur only in testing and not in my emulator or mobile phone. Here is my setupFirebaseAuthMocks. Thank you

my test

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
}

void main() {
 setupFirebaseAuthMocks();
 late ProviderContainer container;

 group('AuthenticationControllerTest -', () {
   setUpAll(() async {
     await Firebase.initializeApp();
     FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
     registerThirdPartyServices();
   });
   tearDown(() {
    unregisterThirdPartyServices();
     //container.dispose();
});
    });

Error

MissingPluginException(No implementation found for method Messaging#getToken on channel plugins.flutter.io/firebase_messaging)

here is the method im trying to call

  Future<Result<Failure, bool>> registerUserFirebaseToken() async {
   try {
    log.i('Registering Firebase');
    final fireBaseMessaging = FirebaseMessaging.instance;
    final token = await fireBaseMessaging.getToken();
    log.v('Firebase token: $token');

  await api.post(
    link: '${env.getValue(kAuthUrl)}users/auth/firebase',
    body: {'token': token},
    hasHeader: true,
  );

  return const Success(true);
} catch (e) {
  return Error(Failure(message: 'Firebase registration went wrong, Please try again!', content: e.toString()));
}

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source