test(coverage): raise unit coverage past the 50% gate (phases 0-2) #27
Reference in New Issue
Block a user
No description provided.
Delete Branch "test/coverage-phase-0-1-2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What & why
After the JaCoCo wiring landed (#26), SonarQube measured new-code coverage at 16.4% — below the 50% quality gate. This executes phases 0–2 of
docs/android/COVERAGE_PLAN.mdto clear it. Estimated new-code coverage after this change: ~57% (measured from the local JaCoCo report with the Sonar coverage-exclusions applied by source file).109 new tests across 19 files; the full suite is now 264 tests, all green.
Phase 0 — coverage exclusions (
sonar-project.properties)Drop code a JVM unit test physically can't execute from the coverage denominator (it stays analysed for bugs/smells): pure-
@ComposableUI the*Screen.ktglob missed (ui/components/**,BlockRenderer,ShardComponents), and Android-framework glue (push foreground services, Keystore-backedEncrypted*stores, Hiltdi/**).Phase 1 — DTO serialization tests
Decode + encode + computed-helper coverage for the previously-untested/partial DTOs:
AdminDto,PublicDto,WikiDto, post/page/contact,SsoDto, the shard board DTOs and player game-data DTOs, and the mobile-auth request bodies — includingisPublished/isMaintenance/ActorDto.label/ShardStatusDto.isOnline, plus theApiResult.map/isShardUnavailablehelpers.Phase 2 — ViewModel tests (the main lever)
A
MainDispatcherRuleharness + hand-written API fakes (FakePublicApi/FakeAdminApi/FakePlayerShardApi/FakeShardStream, no new deps — matches the repo's no-mock convention) drive real repositories into the ViewModels, so repository code is exercised too. Covers:One small production change (no behaviour change)
To make the shard boards unit-testable, a small
ShardStreaminterface is extracted fromShardStreamClient(bound inNetworkModule) soShardRepositorydepends on the capability, not the OkHttp client — a fake stream then replaces the perpetual SSE reconnect loop in tests. Verified withassembleDebug(Hilt graph intact).Deferred (noted as later additions)
Phases 3 (repositories) and 4 (core net/auth top-up) are follow-ups, and the deep-dependency auth family (
LoginViewModel,AccountViewModel,TrustedDevicesViewModel,AuthRepository, which pull inSessionManager/SsoAuthManager/ encrypted stores) lands with them.Verification
./gradlew testDebugUnitTest jacocoTestReport assembleDebug→ BUILD SUCCESSFUL, 264 tests pass. The gate result is confirmed by the post-merge Sonar scan.🤖 Generated with Claude Code