Skip to content

Improve unit test coverage: Firebase, Authenticator, ViewModels, Room DAO#19

Merged
chamika merged 5 commits into
mainfrom
feature/improve-test-coverage
May 9, 2026
Merged

Improve unit test coverage: Firebase, Authenticator, ViewModels, Room DAO#19
chamika merged 5 commits into
mainfrom
feature/improve-test-coverage

Conversation

@chamika
Copy link
Copy Markdown
Owner

@chamika chamika commented May 3, 2026

Summary

  • FirebaseUtils (14 tests): Verifies all safe Crashlytics wrappers (safeRecordException, safeLog, safeSetCustomKey × 3 overloads) delegate correctly and swallow exceptions when GMS is unavailable — the production guard for cars just after an OTA update.
  • Authenticator (13 tests): Covers the Android AccountAuthenticator contract — getAuthToken happy path (cached token), error paths (invalid type, null account, no stored password→intent bundle), and all no-op stubs.
  • SignInViewModel (10 tests): Tests pingServer (200/non-200/exception), login error paths, and loginSuccess side-effects (account storage, loggedIn LiveData) via reflection. Adds core-testing for InstantTaskExecutorRule.
  • SettingsViewModel (10 tests): Verifies logout calls accountManager.logout() and mediaCacheDao.deleteAll(), sends the correct ACTION_STOP_PLAYBACK intent, and clears all six playback-state SharedPreferences keys. Uses a spy on the Robolectric Application to stub startService (Hilt service init is incompatible with unit tests).
  • MediaCacheDao (20 tests): In-memory Room database tests for all DAO operations — insert/replace, queries by ID and parent, parent-ID lookup, sort-order guarantee, partial and full deletion, hasData, and a full entity field round-trip test.
  • Adds androidx-arch-core-testing and androidx-room-testing to the test dependency set.

Before → After: 11/26 source files tested (42%) → 16/26 (62%), adding ~67 new test methods.

Test plan

  • ./gradlew :automotive:testDebugUnitTest — all tests green
  • Each commit tested in isolation before the next was written
  • No production code changed

🤖 Generated with Claude Code

chamika and others added 5 commits May 3, 2026 13:11
Tests verify that all safe wrappers (safeRecordException, safeLog,
safeSetCustomKey) correctly delegate to FirebaseCrashlytics and swallow
exceptions when GMS/Crashlytics is unavailable, preventing app crashes
on cars that just received an OTA update.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests cover token retrieval (happy path and error paths for invalid type
and null account), intent bundle returned when no cached password, and
the no-op/unsupported stubs required by AbstractAccountAuthenticator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests cover pingServer status-200/non-200/exception paths, login error
paths, and the loginSuccess side-effects (account storage and loggedIn
LiveData) via reflection. Adds core-testing for InstantTaskExecutorRule
and room-testing for upcoming DAO tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests verify logout delegates to accountManager and mediaCacheDao, sends
ACTION_STOP_PLAYBACK intent to DashTuneMusicService, and clears all six
playback-state keys from SharedPreferences. Uses a spy on the Robolectric
Application to stub startService (Hilt service initialisation is incompatible
with unit tests) while preserving real SharedPreferences.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests cover all DAO operations: insert/replace, getItem, getChildrenByParent
(including sort-order guarantee), getParentIds, deleteByParent, deleteAll, and
hasData. Also validates that all entity fields round-trip correctly through the
schema, catching any silent type-conversion issues in Room annotations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chamika chamika merged commit 3e9a296 into main May 9, 2026
1 check passed
@chamika chamika deleted the feature/improve-test-coverage branch May 9, 2026 16:46
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.

1 participant