I am running unit tests and I get the following error:
Failed to load "/Users/mathewprasanth/Dev/Flutter/Staffinity/facilify/facilify_ui/test/message_model_test.dart": PlatformException(channel-error, Unable to establish connection on channel., null, null)
package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart 210:7 FirebaseCoreHostApi.initializeCore
===== asynchronous gap ===========================
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 29:44 MethodChannelFirebase._initializeCore
===== asynchronous gap ===========================
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 73:7 MethodChannelFirebase.initializeApp
===== asynchronous gap ===========================
package:firebase_core/src/firebase.dart 43:31 Firebase.initializeApp
===== asynchronous gap ===========================
test/message_model_test.dart 17:3 main
message_model_test.dart:17
===== asynchronous gap ===========================
/var/folders/4v/vjplfnj17lq60v0x252lkv740000gn/T/flutter_tools.4XDyQX/flutter_test_listener.aDKvGa/listener.dart 19:3 _testMain
The unit test code is as follows:
import 'package:facilify_ui/timer/models/message_model.dart';
import 'package:fake_cloud_firestore/fake_cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
late final FakeFirebaseFirestore dbInstance;
setUpAll(() async {
dbInstance = FakeFirebaseFirestore();
});
test('Creating a new instance of MessageModel with all required parameters should succeed', () {
final selfRef = dbInstance.collection('messages').doc('message1');
final created = DateTime.now();
const message = 'Hello, world!';
final userRef = dbInstance.collection('users').doc('user1');
const userName = 'John Doe';
const userImage = 'https://example.com/user1.jpg';
final messageModel = MessageModel(
selfRef: selfRef,
created: created,
message: message,
userRef: userRef,
userName: userName,
userImage: userImage,
);
expect(messageModel.selfRef, equals(selfRef));
expect(messageModel.attachment, isNull);
expect(messageModel.message, equals(message));
expect(messageModel.created, equals(created));
expect(messageModel.userRef, equals(userRef));
expect(messageModel.userName, equals(userName));
expect(messageModel.userImage, equals(userImage));
});
}
I have updated the dependencies and I still get the same problem of platform exception error. Likely related to firebase initialization. I have updated the dependencies and I still get the same problem of platform exception error. Likely related to firebase initialization. I have updated the dependencies and I still get the same problem of platform exception error. Likely related to firebase initialization. I have updated the dependencies and I still get the same problem of platform exception error. Likely related to firebase initialization.