test: add MeshtasticDatabaseTest

This commit is contained in:
andrekir
2024-08-04 11:40:33 -03:00
parent 8bd8bcaffd
commit 6d01fb4bc4
2 changed files with 49 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
package com.geeksville.mesh
import androidx.room.Room
import androidx.room.testing.MigrationTestHelper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.geeksville.mesh.database.MeshtasticDatabase
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.IOException
@RunWith(AndroidJUnit4::class)
class MeshtasticDatabaseTest {
companion object {
private const val TEST_DB = "migration-test"
}
@get:Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MeshtasticDatabase::class.java,
)
@Test
@Throws(IOException::class)
fun migrateAll() {
// Create earliest version of the database.
helper.createDatabase(TEST_DB, 3).apply {
close()
}
// Open latest version of the database. Room validates the schema
// once all migrations execute.
Room.databaseBuilder(
InstrumentationRegistry.getInstrumentation().targetContext,
MeshtasticDatabase::class.java,
TEST_DB
).build().apply {
openHelper.writableDatabase.close()
}
}
}