Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.61 KB

File metadata and controls

38 lines (27 loc) · 1.61 KB

Testing Concepts (platform-agnostic)

This file is shared by mobile-testing-android and mobile-testing-ios. Platform-specific code lives in each skill's SKILL.md.

In-memory databases

Use in-memory databases for unit tests — no disk I/O, no cleanup required.

Both Android (Kotlin) and iOS (Swift) support in-memory databases via DatabaseConfiguration with a temporary directory or the in-memory flag. Each test should create a fresh database and close it in teardown.

What to test

Layer What to test Approach
Document CRUD Read/write/delete correctness In-memory DB, assert content
Queries Result set correctness In-memory DB with seed data
Live queries Change notification firing In-memory DB + listener
Replicator Connection lifecycle Mock replicator or integration test
Conflict resolution Resolver logic Inject two conflicting revisions

Mocking the replicator

The replicator connects to a network endpoint — avoid real network calls in unit tests.

Options:

  • Mock the replicator interface — inject a test double that fires status change events
  • Use a local Sync Gateway — integration tests against a real (local) Sync Gateway
  • URLEndpointListener — use P2P listener as a local server for integration tests

Test isolation principles

  • Each test creates its own database — never share state between tests
  • Seed data explicitly — don't rely on data left by previous tests
  • Close and delete databases in teardown — prevent file handle leaks
  • Use deterministic document keys — avoid random IDs that make assertions fragile