簡體   English   中英

如何從 firebase_auth 測試“signInWithEmailAndPassword”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM