Skip to main content
Cindel is designed to be test-friendly. The 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:
Always call 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.
Give each test its own openInMemory instance rather than sharing a single database across tests. Isolated databases make failures easier to diagnose and prevent one test’s writes from affecting another.

What to Test

Cover the operations your application actually relies on:
  • CRUDput, get, delete, putAll, getAll
  • Querieswhere() helpers for indexed fields, filter() for arbitrary predicates
  • Aggregatescount() for pagination guards and empty-state logic
  • Sorting and pagination — verify that sort order and page limits produce the expected results
CRUD example
Query example
Count example

Widget Tests

Use openInMemory inside testWidgets exactly as you would in a unit test. Pass the database to your widget tree and pump normally:
Keep database setup close to the test so each test controls its own data and there is no hidden shared state.
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 a FakeSyncAdapter that lets you control online/offline state deterministically. Toggle online before each assertion instead of relying on arbitrary sleep calls:
Wire the fake adapter into a database opened with a real directory (not in-memory, so you can test close/reopen and persistence), and use a short sync interval to keep tests fast:
Useful sync cases to cover:
  • A local write is visible immediately, even while offline
  • A pending write survives close and reopen
  • 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

Use openInMemory 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