我正在尝试在我的 Flutter 应用程序中编写一些单元测试。我正在使用firebase,我编写了这个函数(我想测试):
import 'dart:core';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart';
class FirebaseUtils {
static final FirebaseAuth _auth = FirebaseAuth.instance;
static Exception _exception;
static Future<bool> signIn(String email, String password) async {
FirebaseUser user;
try{
user = await _auth.signInWithEmailAndPassword(email: email, password: password);
} catch (ex){
print(ex);
_exception = ex;
user = null;
}
return user!=null;
}
}
我的测试:
import "package:test/test.dart";
import 'package:toolpad/utils/firebase/firebase_utils.dart';
import 'dart:async';
void main() {
test("Sign In user from firebase (working)", () async {
bool result = await FirebaseUtils.signIn("test@gmail.com", "lollollol");
expect(result, equals(true));
});
}
当我启动抛出异常的测试时:
MissingPluginException(No implementation found for method signInWithEmailAndPassword on channel plugins.flutter.io/firebase_auth)
ERROR: Expected: <true>
Actual: <false>
我不知道如何解决它,有人有想法吗?