Connecting Firestore emulator to flutter_test

358

As far as I know, Firebase does not support unit tests in Flutter because it is a plugin that requires native integration.

The tests in the Flutter Firebase repo are run in main.dart, not unit tests.

Share:
358
Volodymyr Bobyr
Author by

Volodymyr Bobyr

Updated on December 21, 2022

Comments

  • Volodymyr Bobyr
    Volodymyr Bobyr over 1 year

    I'm setting up integration tests for a Flutter app and having trouble connecting them to an instance of a Firestore emulator.

    Here's my code:

    import 'package:cloud_firestore/cloud_firestore.dart';
    import 'package:flutter_test/flutter_test.dart';
    
    void main() {
      TestWidgetsFlutterBinding.ensureInitialized();
      Firestore firestore;
    
      setUp(() async {
        firestore = Firestore.instance;
        await firestore.settings(host: 'http://localhost:4000/firestore');
      });
    
      group('some group', () {
        test('some test', () async {
          print('yo');
        });
      });
    }
    

    When I run it, I get the following error:

    ERROR: MissingPluginException(No implementation found for method Firestore#settings on channel plugins.flutter.io/cloud_firestore)
    package:flutter/src/services/platform_channel.dart 154:7  MethodChannel._invokeMethod
    

    Any suggestions on how to address this?