Write Unit test case for Hive in flutter mobile app
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
I am using Hive flutter plugin for local storage. I want to write unit test for the same. But I can not Mock the Hive Object and test it.
**Describe the solution you'd like**
I am using the given below code to store and get data from local storage. When I am trying to write unit test case, i am not able to mock Hive object to test. Please provide some sample to write unit test case for. the below scenario.
'
Future initHive() async {
await Hive.initFlutter();
}
Future storeData(
String storageKey, dynamic value}) async {
var storageBox = await Hive.openBox('data');
storageBox.put(storageKey, value);
}
Future getStoredData(String storageKey) async {
var storageBox = await Hive.openBox('data');
var value = storageBox.get(storageKey);
return value;
}
'
**Describe alternatives you've considered**
**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: 1.12.13+hotfix.8
- Hive version: 1.4.1+1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the issue's initHive, storeData, and getStoredData examples, then read the Hive and Flutter testing guidance to determine how Hive.openBox can be exercised. Done means providing a documented sample that explains how to test these operations, including the limitation around mocking Hive objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- databases, mobile, testing
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100