dimanche 18 novembre 2018

How can I access the Firebase Flutter plugin from a test?

I want to run Firebase during a Flutter test. I'm trying to authenticate Firebase with FirebaseOptions:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import "package:test/test.dart";

Future<void> main() async {
  final FirebaseApp app = await FirebaseApp.configure(
    name: 'test',
    options: const FirebaseOptions(
      googleAppID: 'xxxxxxx',
      projectID: 'yyyyyy',
    ),
  );
  final Firestore firestore = Firestore(app: app);
  await firestore.settings(timestampsInSnapshotsEnabled: true);

  test('Testing access.', () async {
    final FirebaseAuth _auth = FirebaseAuth.instance;
    FirebaseUser user = await _auth.signInAnonymously();

    firestore.collection('aaaaa').document('bbbbb').get().then((documentSnaphot) {
      expect(documentSnaphot['xxxx'], 'ccccc');
    });
  });
}

However, I'm getting the following error:

Failed to load "C:\Users\Ed\testing\app\test\user_test.dart": 
MissingPluginException(No implementation found for method 
FirebaseApp#appNamed on channel plugins.flutter.io/firebase_core)


package:flutter/src/services/platform_channel.dart 278:7                                                    
MethodChannel.invokeMethod

===== asynchronous gap ===========================

c: 38:53                                                                                                    
FirebaseApp.appNamed

===== asynchronous gap ===========================

c: 64:55                                                                                                    
FirebaseApp.configure

===== asynchronous gap ===========================

test\usuario_test.dart 7:45                                                                                 
main

===== asynchronous gap ===========================

package:test                                                                                                
serializeSuite

..\..\..\AppData\Local\Temp\flutter_test_listener.64a30b51-eb69-11e8-
a427-1831bf4c06e8\listener.dart 19:27  main

How can I solve this?

Aucun commentaire:

Enregistrer un commentaire