Skip to content

test: add comprehensive unit tests for :core:datastore module - #1590

Open
fpMiguel wants to merge 4 commits into
Futsch1:mainfrom
fpMiguel:datastore-unit-tests
Open

test: add comprehensive unit tests for :core:datastore module#1590
fpMiguel wants to merge 4 commits into
Futsch1:mainfrom
fpMiguel:datastore-unit-tests

Conversation

@fpMiguel

@fpMiguel fpMiguel commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Adds 92 JVM unit tests to :core:datastore — the module previously had no direct
tests. Covers PreferencesDataSource (32), PersistentDataDataSource (48) and
BackupMapper (12) with edge-case coverage, and moves the existing datastore tests
from :app into the module where the code under test lives.

Changes

File Change
core/datastore/build.gradle.kts Robolectric/JUnit test configuration + test dependencies
gradle/libs.versions.toml Added androidx.test:core to the version catalog
core/datastore/src/test/.../BackupMapperTest.kt 12 tests — toSettingsBackup mapping + applyTo integration
core/datastore/src/test/.../PreferencesDataSourceTest.kt 32 tests — roundtrips, enum parsing, preference overrides, Flow emission
core/datastore/src/test/.../PersistentDataDataSourceTest.kt 48 tests — setters, notification IDs, pending-snooze CRUD, data Flow
app/src/test/.../location/ (deleted) Removed — tests moved to :core:datastore where the code under test lives

Notes

  • Test infrastructure: Robolectric + JUnit 4 + kotlinx-coroutines-test
  • Per review feedback, default-value tests and tests that merely re-state Android
    SharedPreferences behavior were removed
  • Note: AI assistance was used in drafting this code and/or tests.

@Futsch1 Futsch1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@fpMiguel
Thank you for your contribution! Your PR is still draft, so I cannot merge it yet. I will look into all of your PRs and review them. Once they are all approved and good to merge, I will do this all in one go to come to a working state of tests again.

Oh, and it would be great to disclose if you used AI to generate the PRs.

141 JVM unit tests across 3 test classes covering:
- PreferencesDataSourceTest: default values, roundtrips,
  enum parsing, flow emission, PreferenceDataStore overrides
- PersistentDataDataSourceTest: defaults, setters, notification ID,
  pending snooze CRUD, StatisticFragment mapping, data flow
- BackupMapperTest: toSettingsBackup mapping, applyTo roundtrip

134 pass, 7 intentionally fail documenting production code bugs.
Also removes duplicated datastore tests from :app module and
uses version catalog for androidx.test:core dependency.
The bugs they documented were fixed in the merged PreferencesDataSource
and PersistentDataDataSource PRs; the tests now pass and the comments were
stale.
@fpMiguel
fpMiguel force-pushed the datastore-unit-tests branch from fc450d1 to 77b395d Compare August 8, 2026 20:03
@fpMiguel
fpMiguel marked this pull request as ready for review August 10, 2026 19:49
@fpMiguel
fpMiguel requested a review from Futsch1 August 10, 2026 19:49
Comment thread core/datastore/build.gradle.kts
@fpMiguel
fpMiguel requested a review from Futsch1 August 26, 2026 05:58
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.

2 participants