Skip to content

Add public API unit tests with ≥80% coverage (#30)#34

Merged
itsniper merged 1 commit into
masterfrom
30-write-unit-tests
Jun 28, 2026
Merged

Add public API unit tests with ≥80% coverage (#30)#34
itsniper merged 1 commit into
masterfrom
30-write-unit-tests

Conversation

@itsniper

Copy link
Copy Markdown
Member

Closes #30 (NFR-2.1).

Summary

Expands ReliaBLETests to give every public method and property on ReliaBLEManager — plus the public value types — at least one behavioral test, reaching ≥80% code-path coverage of Sources/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).
  • Value types: BluetoothState.description for every case, Peripheral / PeripheralDiscoveryEvent id-based equality & hashing, AdvertisementData typed extraction (full + empty), ReliaBLEConfig defaults, and the logging module (LoggingService, LogMessage, OSLogWriter).

Test design

All BLE paths run against Nordic's CBMCentralManagerMock through the existing three-target SPM trick (forceMock: true) — no real CoreBluetooth hardware.

Because BluetoothActor.shared is a process-lifetime singleton and the mock keeps global static state, the tests live in a single @Suite(.serialized). A one-shot SimulationConfig registers the simulated peripheral and pins authorization before any central is created; an ensureReady helper re-establishes a known baseline per test, so the suite is order-independent and stable across repeated runs.

Adds CoreBluetoothMock and Willow as test-target dependencies.

Coverage

Measured with swift test --enable-code-coverage + llvm-cov report on macOS:

Metric Sources/ReliaBLE/
Line 91.76%
Region 87.89%
Function 92.31%

Per file: ReliaBLEManager 100%, ReliaBLEConfig 100%, Peripheral/AdvertisementData 100%, Logging 100%, BluetoothActor 87.7% line / 82.0% region, PeripheralDiscoveryEvent 94.1% line.

Remaining uncovered paths are the hard-to-simulate ones (central .resetting/.unsupported/.unauthorized invalidation, the @unknown default assertion, and "no central manager" guards unreachable once the singleton central exists).

Acceptance criteria

  • Every public method/property on ReliaBLEManager has a behavioral test.
  • swift test passes on macOS with zero failures (27 tests).
  • Coverage of Sources/ReliaBLE/ ≥ 80%.
  • Tests follow conventions: Swift Testing (@Test), @testable import ReliaBLEMock, no real CoreBluetooth hardware.

🤖 Generated with Claude Code

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ReliaBLEManager authorization, scanning/discovery, connection, and stream replay semantics using CBMCentralManagerMock.
  • Adds direct behavioral tests for public value/logging types (BluetoothState.description, Peripheral / PeripheralDiscoveryEvent identity semantics, AdvertisementData, ReliaBLEConfig defaults, LoggingService / LogMessage / OSLogWriter).
  • Updates ReliaBLETests target dependencies to include Willow and CoreBluetoothMock so 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.

@itsniper itsniper merged commit 2ebe5d1 into master Jun 28, 2026
2 checks passed
@itsniper itsniper deleted the 30-write-unit-tests branch June 28, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NFR-2.1: Unit tests for public API (≥80% coverage)

2 participants