Package selection guidance compiled from public package information, community data, and project usage.
A testing package that provides mock implementations for Firebase Authentication, enabling developers to simulate authentication flows without connecting to the actual Firebase backend. It works alongside `google_sign_in_mocks` to facilitate unit testing of authentication-related logic in Flutter apps. Ideal for testing login, sign-out, and user state changes in a controlled environment. The package supports all major platforms including Android, iOS, Web, macOS, and Windows, ensuring consistent test behavior across environments.
Use cases
Unit testing authentication flows
Simulating user sign-in and sign-out
Testing app behavior under different auth states
Validating UI updates based on user authentication
Developing offline test scenarios
Key features
Mock FirebaseAuth instance
Integration with google_sign_in_mocks
Platform-agnostic testing
Supports all Flutter platforms
Easy setup for test environments
Suitable for
Flutter developers writing tests
Teams practicing TDD or BDD
Apps relying heavily on Firebase Auth
Test-driven development workflows
CI/CD pipelines requiring reliable tests
Considerations
Not for production use
Requires companion google_sign_in_mocks
Mock behavior may not reflect real-world edge cases
Limited to basic auth state simulation
Does not support real-time auth listeners
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
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.