Posts

Showing posts from April, 2020

Test your database

Overview In this post I'd like to show you how to test your database. I try to be abstract and general enough, though I want this post to be a basic example for a real life case you can build upon. I assume you're familiar with the official Flutter  SQLite cookbook . Stay with me if you haven't tested your database yet. Setup First of all, you'll need two dependencies: sqflite: ^1.3.0 path: ^1.7.0 and one test file in path/to/app/test/db/db_test.dart and one class file in path/to/app/lib/db/db.dart. Path is the dependency of my choice, but there are alternatives to it; sqflite is the most common choice for a SQLite database for Flutter, and there are alternatives to it too, the most interesting one being  Moor . The database class In db.dart you can define your wrapper around the SQLite database, namely DBManager. I chose to implement it as a singleton, because you want to access the database manager from anywhere in your code: class DBManager {   st...