I just realized that I can't create an in-memory d...
# kotlin-native
s
I just realized that I can't create an in-memory database using SqlDelight for writing unit tests. How are folks writing tests that talk to a storage layer?
r
Yes you can. The configuration is engine-specific, and a little verbose in native, but here's what it looks like in a project I'm working on Android: https://github.com/russhwolf/soluna/blob/master/soluna-mobile/shared/src/androidTest/kotlin/TestDependencies.kt#L15-L16 Ios: https://github.com/russhwolf/soluna/blob/master/soluna-mobile/shared/src/iosTest/kotlin/TestDependencies.kt#L18-L33
s
Interesting. When you run a test written in kotlin native, does it actually run on JVM? How are you able to use an Android class with them?
r
The test runs in Android with Robolectric on the JVM (or SqlDelight also has a
JdbcSqliteDriver
you can use for running on JVM with no Android dependency). On iOS it runs natively on simulator. The links above are
actual
declarations for an
expect
function so there can be different driver configurations per-platform. Then all the rest of the test logic can live in common and be shared
Just realized I confused things a little because you were just asking about native, not multiplatform. So you can ignore the Android side and just look at the iOS implementation
s
I see what you're doing. I did not think of providing actual implementation using Android/iOS classes for kotlin/native tests. This gives me a head start. I'll try this and report back, thank you!
This worked, thanks @russhwolf!
👍 1