실제 Firebase 백엔드에 연결하지 않고 인증 흐름을 시뮬레이션할 수 있도록 Firebase 인증을 위한 모의 구현을 제공하는 테스트 패키지입니다. `google_sign_in_mocks`와 함께 사용하여 Flutter 앱에서 인증 관련 로직의 단위 테스트를 용이하게 합니다. 제어된 환경에서 로그인, 로그아웃 및 사용자 상태 변경을 테스트하는 데 이상적입니다. Android, iOS, Web, macOS, Windows 등 모든 주요 플랫폼을 지원하여 환경 간 일관된 테스트 동작을 보장합니다.
A simple usage example. Add firebase_auth_mocks and google_sign_in_mocks to dev dependencies.
import'package:firebase_auth_mocks/firebase_auth_mocks.dart';
import'package:google_sign_in_mocks/google_sign_in_mocks.dart';
main() {
// Mock sign in with Google.final googleSignIn = MockGoogleSignIn();
final signinAccount = await googleSignIn.signIn();
final googleAuth = await signinAccount.authentication;
finalAuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Sign in.final user = MockUser(
isAnonymous: false,
uid: 'someuid',
email: 'bob@somedomain.com',
displayName: 'Bob',
);
final auth = MockFirebaseAuth(mockUser: user);
final result = await auth.signInWithCredential(credential);
final user = await result.user;
print(user.displayName);
}
Features
MockFirebaseAuth supports:
instantiating in a signed-in state or not: MockFirebaseAuth(signedIn: true/false).
firing events on sign-in to authStateChanges and userChanges.
signInWithCredential, signInWithEmailAndPassword, signInWithCustomToken,
signInAnonymously, createUserWithEmailAndPassword, signInWithPopup and signInWithProvider signs in.
sendSignInLinkToEmail, confirmPasswordReset and verifyPasswordResetCode.
verifyPhoneNumber resolves codeSent.
signOut
sendPasswordResetEmail
currentUser
the ability to throw exceptions using whenCalling(...).on(...).thenThrow(...). See usage details below. Currently these methods are supported: signInWithCredential, signInWithPopup, signInWithProvider, signInWithEmailAndPassword, createUserWithEmailAndPassword, signInWithCustomToken, signInAnonymously, signOut, sendPasswordResetEmail, sendSignInLinkToEmail, confirmPasswordReset, verifyPasswordResetCode. If you need another method supported, feel free to file a ticket, or better propose a PR.
pass auth information (uid, custom claims...) to Fake Cloud Firestore for security rules via authForFakeFirestore. See the docs at fake_cloud_firestore for usage.