简体   繁体   中英

Can't create unit test with FireStore for flutterfire, throws during init, even with simplest possible test

// ignore_for_file: avoid_print
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('core tests - coffee', () {
    test('fetch coffees', () async {
      await Firebase.initializeApp();
      final FirebaseFirestore firestore = FirebaseFirestore.instance;

      print('initialized');
      expect(firestore, isNotNull);
    });
  });
}

This is in a test. Oddly, it works in the live app, but not in a simple test case. Errors during Firebase.initializeApp() with:

Null check operator used on a null value
MethodChannel.binaryMessenger
package:flutter/…/services/platform_channel.dart:121

I don't want a testWidgets. I don't want a mocked FireStore. I want to hit the real database.

I'm on a mac, running a simulator, using VSC, although the simulator shouldn't even be involved.

Firebase plugins wraps around native platform (firebase) SDKs and i think they are not available on when running tests. I would suggest to use either the emulator suite or fake_cloud_firestore package, or do manual testing by humans (connected with a different firebase instance)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM