mock

fun CentralManager.Factory.mock(environment: MockAndroidEnvironment = LatestApi(), scope: CoroutineScope, clock: Clock = Clock.System): MockCentralManager

Creates a mock implementation of a CentralManager that can emulate scanning and connecting to Bluetooth Low Energy devices.

Use MockCentralManager.simulatePeripherals to set up mock peripherals and other methods from SimulationProvider to control the simulation.

Advertising and the background work of the simulated peripherals, like link loss or notifications, run in the given scope. A scope backed by a test dispatcher, e.g. backgroundScope of runTest, makes them follow the test scheduler and its virtual time.

Parameters

environment

The environment to use for the mock, defaults to the latest supported API.

scope

The coroutine scope.

clock

The clock used for timestamps of scan results, defaults to the system clock. Tests using virtual time may pass a clock based on the test scheduler.