firebase_database_mocks
0.9.0, released 4 weeks ago by berete.dev
Mock library to write unit tests for Firebase Realtime Database.
What it does
Provides a mock implementation of FirebaseDatabase that keeps data in memory during tests. Allows developers to pre-populate fake data and test read, write, update, and remove operations without connecting to a live Firebase backend.
AI-written summary of version 0.9.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to write unit tests for code interacting with Firebase Realtime Database.
- You want to test Firebase database interactions without network latency or live credentials.
Skip it when
- You are using backend services other than Firebase Realtime Database.
- You require complex database features or event types not supported by the mock library.
Strengths
- Enables simple in-memory unit testing for FirebaseDatabase.
- Requires no Firebase initialization or TestWidgetsFlutterBinding for basic usage.
- Supports common database operations like ref, child, get, set, update, remove, and once.
Weaknesses
- Data persistence disabling feature is currently experimental and may have issues.
- Only supports `DatabaseEventType.value` for `once()`.
- Limited to a subset of getters and methods defined in the mock classes.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
not documented
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database_mocks/firebase_database_mocks.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Should get user name', () async {
const fakeData = {
'users': {
'userId': {
'name': 'Elon musk',
}
}
};
MockFirebaseDatabase.instance.ref().set(fakeData);
final snapshot = await MockFirebaseDatabase.instance.ref().child('users/userId/name').once();
expect(snapshot.snapshot.value, equals('Elon musk'));
});
}Alternatives
Packages that do the same job and could replace firebase_database_mocks.
- firebase_storage_mocks
Mocks for Firebase Storage to write unit tests.
82Compare - fake_cloud_firestore
Fake implementation of Cloud Firestore for unit testing.
87Compare - google_sign_in_mocks
Mocks for Google Sign In to write unit tests for authentication.
73Compare - convenient_test
Write and debug Flutter tests with action history, time travel, screenshots, and video records.
76Compare
Works with
Packages commonly used together with firebase_database_mocks: ones it builds on, ones built on it, and its own family.