Testing
In some tests (like verification of migrations) you might wish to swap out the Android driver with the JVM driver, enabling you to test code involving the database without needing an Android emulator or physical device. To do that use the jvm SQLite driver:
dependencies {
testImplementation("app.cash.sqldelight:sqlite-driver:2.1.0-SNAPSHOT")
}
dependencies {
testImplementation "app.cash.sqldelight:sqlite-driver:2.1.0-SNAPSHOT"
}
// When your test needs a driver
@Before fun before() {
driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
Database.Schema.create(driver)
}
If you are using the SQLite that comes bundled with Android (rather than shipping your own), you can override the version of sqlite-jdbc to one that matches your Android minSdkVersion, for example for API 23 use SQLite 3.8.10.2:
dependencies {
testImplementation('org.xerial:sqlite-jdbc') {
// Override the version of sqlite used by sqlite-driver to match Android API 23
version { strictly('3.8.10.2') }
}
}