```
Room 测试
-
在
androidTest
文件夹下新建测试类```
@RunWith(AndroidJUnit4::class)
class WordDaoTest {
private lateinit var database: AppDataBase
private lateinit var wordDao: WordDaoprivate val word1 = Word("hello") private val word2 = Word("world") @get:Rule var instantTaskExecutorRule = InstantTaskExecutorRule() @Before fun createDb() = runBlocking { val context = InstrumentationRegistry.getInstrumentation().targetContext database = Room.inMemoryDatabaseBuilder(context, AppDataBase::class.java).build() wordDao = database.wordDao() wordDao.insertAll(listOf(word1, word2)) } @After fun closeDb() { database.close() } @Test fun testGetAlphabetizedWords() = runBlocking { val wordList = wordDao.getAlphabetizedWords().first() Assert.assertThat(wordLi