StanfordSpezi / SpeziBluetooth

Connect and communicate with Bluetooth devices.
https://swiftpackageindex.com/StanfordSpezi/SpeziBluetooth/documentation/spezibluetooth
MIT License
11 stars 2 forks source link

Enable Mocking a Bluetooth Connection & Testing in SpeziBluetooth #3

Closed PSchmiedmayer closed 2 months ago

PSchmiedmayer commented 1 year ago

Problem

The current implementation of the Spezi Bluetooth module includes a limited test coverage and, unfortunately, offers a limited capability for users to mock their Bluetooth devices in UI or unit tests in their Swift Packages or applications.

Solution

We should enable a mocking behavior in Spezi Bluetooth.

https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock looks like a promising library that can be used to mock CoreBluetooth and provide this API surface to users of SpeziBluetooth and should be used to communicate with core Bluetooth with a mechanism to enable mocking behavior in the current implementation.

Additional context

The following example provides a good starting point: https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock-Example

Code of Conduct

Supereg commented 2 months ago

We decided against using a Wrapper library around CoreBluetooth like the one developed from Nordic. We use on Objective C KVO to receive updates form CoreBluetooth. This is not properly forwarded from the Nordic library. Further, we opted to have an CI setup that executes unit tests with a real-world bluetooth peripheral. Further, the SpeziBluetooth DSL has extensive support to inject behavior or mock values making it possible for users of the library to easily test their implementations. This is great for users for SpeziBluetooth as it improve testability for their applications and removes the need to to build extensive setups.