My team and I have been writing unit tests for our Flutter App. We've used mockito to write unit tests for our providers. Now we're trying to write unit tests for database calls. How can we test our database calls?
CodePudding user response:
This might be what you need. Using the sqflite_ffi
package to create your database.
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
Future main() async {
late Database database;
// Setup sqflite_common_ffi for flutter test
setUpAll(() {
// Initialize FFI
sqfliteFfiInit();
// Change the default factory for unit testing calls for SQFlite
databaseFactory = databaseFactoryFfi;
database = Database();
});
tearDownAll(() {
// Maybe delete the database here
});
// Tests here
test('Example test'(){
//Do your database calls here, query, delete, etc
});
}