When using Room AutoMigrations, the Migration
itself is automatically generated. But in order to unit test the migration, I have to pass a Migration
object to runMigrationsAndValidate
. What should I pass here?
@RunWith(AndroidJUnit4::class)
class MigrationTest {
private val TEST_DB = "migration-test"
@Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MigrationDb::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
)
@Test
@Throws(IOException::class)
fun migrate1To2() {
var db = helper.createDatabase(TEST_DB, 1).apply {
// db has schema version 1. insert some data using SQL queries.
execSQL(...)
// Prepare for the next version.
close()
}
// Re-open the database with version 2 and provide
// Migration as the migration process.
db = helper.runMigrationsAndValidate(TEST_DB, 2, true, /* WHAT TO PASS HERE? */)
}
}