12

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.

1
  • 2
    Facing the same issue, were you able to find a solution? Commented Oct 16, 2020 at 6:07

1 Answer 1

6

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)

Sign up to request clarification or add additional context in comments.

1 Comment

great answer just to add that flutter fire does mention this in their own docs firebase.flutter.dev/docs/testing/testing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.