Given that Room supports Jvm thanks to KMP support...
# room
o
Given that Room supports Jvm thanks to KMP support. In the context of a pure Android project, not using KMP. Would it be possible to use Room Jvm runtime on Jvm unit tests? I tried the following in an Android library Gradle module
Copy code
implementation(libs.androidx.room.common)
    testImplementation(libs.androidx.room.runtime.jvm)
    testImplementation(libs.androidx.sqlite.jvm)
    testImplementation(libs.androidx.room.testing)
But the
inMemoryDatabaseBuilder
function references the Android
Context
, it comes from the Android runtime dependency despite not being referenced. How could I manage to run Unit tests using Dao with in-memory DB on Jvm unit test with an Android library module?
Oh 🎉 I finally, managed to make it work. I think, I had some Gradle sync/build cache issues at some point leading to false positive. Here is the final setup to make it work
Copy code
implementation(libs.androidx.room.common)

    testImplementation(libs.androidx.room.runtime.jvm)
    testImplementation(libs.androidx.sqlite.jvm)
    testImplementation(libs.androidx.sqlite.bundled.jvm)
Copy code
db = Room.inMemoryDatabaseBuilder<UserPreferencesDatabase>()
    .setDriver(BundledSQLiteDriver())
    .build()