![](/img/trans.png)
[英]Flutter firebase_auth hassle with deprecated code (From 0.16 to 1.0)
[英]How to test "signInWithEmailAndPassword" from firebase_auth
我正在尝试在我的 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>
我不知道如何解决它,有人有想法吗?
经过大量搜索后,如果不指定 Firebase.initialize 之前似乎是不可能的。
所以如果你想测试一些链接到 Firebase 的功能,你应该使用testWidget
。 这将测试您的应用程序而不是 juste 功能)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.