Cindel.openInMemory API gives every test its own temporary database that uses the same generated typed API as your production code, so tests are fast, isolated, and trust-worthy. You don’t need a device, an emulator, or any disk setup — just the schemas your test cares about.
Unit and Package Tests
Open an in-memory database at the start of each test and register only the schemas that test needs:addTearDown(db.close) (or close in tearDown) so the database is cleaned up even when an expectation fails mid-test. On Web, openInMemory uses a unique browser database name for each session, so closing is especially important to avoid state leaking between test runs.
What to Test
Cover the operations your application actually relies on:- CRUD —
put,get,delete,putAll,getAll - Queries —
where()helpers for indexed fields,filter()for arbitrary predicates - Aggregates —
count()for pagination guards and empty-state logic - Sorting and pagination — verify that sort order and page limits produce the expected results
Widget Tests
UseopenInMemory inside testWidgets exactly as you would in a unit test. Pass the database to your widget tree and pump normally:
Keep
cindel_flutter_libs in dependencies — not dev_dependencies — even when your tests use in-memory databases. This ensures integration tests and platform builds share the same package graph as the app, and that flutter test loads the native libraries correctly.Sync Testing
Test sync behavior with aFakeSyncAdapter that lets you control online/offline state deterministically. Toggle online before each assertion instead of relying on arbitrary sleep calls:
- A local write is visible immediately, even while offline
- A pending write survives
closeandreopen - A backend correction applies locally after the adapter comes back online
- A delete replicates to another client
- A remote apply does not create a second local pending mutation
- Unsupported operations fail with a clear error
When to Use a Persistent Temp Directory
UseopenInMemory for the vast majority of your tests. Reach for a persistent temporary directory (for example, via path_provider’s temp dir) only when the test specifically needs:
- Close/reopen behavior — verify data survives a database restart
- File persistence — check that files appear on disk after a write
- Backup and restore — test full archive export/import flows
- Sync restart behavior — confirm pending mutations survive a process restart