database: TodoDatabase @Before fun openDatabase() { database = Room .inMemoryDatabaseBuilder( InstrumentationRegistry.getInstrumentation().targetContext, TodoDatabase::class.java ).allowMainThreadQueries() .build() } @After fun closeDatabase() { database.close() } @Test @Throws(Exception::class) fun insert() { assertThat(database.todoDao().count(), `is`(0)) val list = listOf( TodoEntity( name = "Robolectric͏", category = 1 ), TodoEntity( name = "JUnit͏", category = 1 ) ) database.todoDao().upsertAll(list) assertThat(database.todoDao().count(), `is`(2)) } } @Test @Throws(Exception::class) fun insert() { assertThat(database.todoDao().count(), `is`(0)) val list = listOf( TodoEntity( name = "Robolectric͏", category = 1 ), TodoEntity( name = "JUnit͏", category = 1 ) ) database.todoDao().insertAll(list) assertThat(database.todoDao().count(), `is`(2)) }