Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) on tests

we are using the new version of FlutterFire, but we have some issues when running our tests, we managed to initialise Firebase adding this:

setUp(() async {
    TestWidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
  });

But now we have this error message:

MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
  package:flutter/src/services/platform_channel.dart 159:7  MethodChannel._invokeMethod

The app runs well both on iOS and Android, we only have the issue when running the widget tests. We've tried with Flutter stable and dev channels.

like image 799
chsanch Avatar asked Sep 29 '20 11:09

chsanch


1 Answers

I'm assuming you are performing either unit or widget testing. Just take a look at how the plugin itself is being tested.

class FakeFirebaseAppPlatform extends Fake implements FirebaseAppPlatform {}

They just fake the object.

Why? because this plugin is implemented using method channels and while testing you don't have access to the native platform .Your only option is to mock or fake your interactions with Firebase either:

  1. As the authors of the plugin are doing using Mockito

  2. Mock the method channel as illustrated in this answer , (which is in my opinion more cumbersome, and best suited if you are developing a plugin yourself)

like image 175
croxx5f Avatar answered Sep 28 '22 02:09

croxx5f