Add public API unit tests with ≥80% coverage (#30)#34
Merged
Conversation
Expand ReliaBLETests to exercise every public method and property on ReliaBLEManager plus the public value types, closing NFR-2.1 (#30). - Drive authorization, scanning, discovery, and connection paths through Nordic's CBMCentralManagerMock via the existing three-target SPM trick (forceMock: true), with no real CoreBluetooth hardware. - Unify all tests into a single @suite(.serialized): the process-wide BluetoothActor singleton and the mock's global state make parallel execution unsafe (a scan in one test would feed another's discovery subscriber). A one-shot SimulationConfig registers the simulated peripheral and pins authorization before any central is created, and an ensureReady helper re-establishes a known baseline per test, so the suite is order-independent. - Cover the public value types directly: BluetoothState.description for every case, Peripheral/PeripheralDiscoveryEvent id-based equality and hashing, AdvertisementData typed extraction, ReliaBLEConfig defaults, and the logging module (LoggingService, LogMessage, OSLogWriter). - Add CoreBluetoothMock and Willow as test-target dependencies. Measured coverage of Sources/ReliaBLE/: 91.76% line / 87.89% region (ReliaBLEManager 100%, BluetoothActor 87.7% line). swift test passes with zero failures. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the ReliaBLETests target to provide behavioral coverage for the public surface area of ReliaBLEManager and key public value/logging types, aligning with NFR-2.1’s ≥80% coverage goal while keeping BLE interactions fully mocked.
Changes:
- Adds a serialized Swift Testing suite that exercises
ReliaBLEManagerauthorization, scanning/discovery, connection, and stream replay semantics usingCBMCentralManagerMock. - Adds direct behavioral tests for public value/logging types (
BluetoothState.description,Peripheral/PeripheralDiscoveryEventidentity semantics,AdvertisementData,ReliaBLEConfigdefaults,LoggingService/LogMessage/OSLogWriter). - Updates
ReliaBLETeststarget dependencies to includeWillowandCoreBluetoothMockso tests can import and drive the mock + logging types directly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Tests/ReliaBLETests/ReliaBLEManagerTests.swift | Adds a serialized end-to-end mock-driven test harness covering ReliaBLEManager’s public API and public value/logging behaviors. |
| Package.swift | Adds Willow and CoreBluetoothMock as explicit ReliaBLETests dependencies to support the new test imports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #30 (NFR-2.1).
Summary
Expands
ReliaBLETeststo give every public method and property onReliaBLEManager— plus the public value types — at least one behavioral test, reaching ≥80% code-path coverage ofSources/ReliaBLE/.What's covered
ReliaBLEManager:init(config:),loggingService,state/currentState,authorizeBluetooth()(denied / restricted / allowed / cancellation),startScanning/stopScanning(lifecycle + not-powered-on no-op),peripheralDiscoveries,discoveredPeripherals(replay + live updates),connect(to:)(success + unknown).BluetoothState.descriptionfor every case,Peripheral/PeripheralDiscoveryEventid-based equality & hashing,AdvertisementDatatyped extraction (full + empty),ReliaBLEConfigdefaults, and the logging module (LoggingService,LogMessage,OSLogWriter).Test design
All BLE paths run against Nordic's
CBMCentralManagerMockthrough the existing three-target SPM trick (forceMock: true) — no real CoreBluetooth hardware.Because
BluetoothActor.sharedis a process-lifetime singleton and the mock keeps global static state, the tests live in a single@Suite(.serialized). A one-shotSimulationConfigregisters the simulated peripheral and pins authorization before any central is created; anensureReadyhelper re-establishes a known baseline per test, so the suite is order-independent and stable across repeated runs.Adds
CoreBluetoothMockandWillowas test-target dependencies.Coverage
Measured with
swift test --enable-code-coverage+llvm-cov reporton macOS:Per file:
ReliaBLEManager100%,ReliaBLEConfig100%,Peripheral/AdvertisementData100%, Logging 100%,BluetoothActor87.7% line / 82.0% region,PeripheralDiscoveryEvent94.1% line.Remaining uncovered paths are the hard-to-simulate ones (central
.resetting/.unsupported/.unauthorizedinvalidation, the@unknown defaultassertion, and "no central manager" guards unreachable once the singleton central exists).Acceptance criteria
ReliaBLEManagerhas a behavioral test.swift testpasses on macOS with zero failures (27 tests).Sources/ReliaBLE/≥ 80%.@Test),@testable import ReliaBLEMock, no real CoreBluetooth hardware.🤖 Generated with Claude Code