Created
May 7, 2019 01:27
-
-
Save Levi-Moreira/9f363901fd60df35d9090fbaaedd73b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class SampleTest { | |
private lateinit var personDao: PersonDao | |
private lateinit var db: AppDatabase | |
@Before | |
fun createDb() { | |
db = Room.inMemoryDatabaseBuilder( | |
InstrumentationRegistry.getContext(), AppDatabase::class.java).build() | |
personDao = db.personDao() | |
} | |
@After | |
@Throws(IOException::class) | |
fun closeDb() { | |
db.close() | |
} | |
@Test | |
@Throws(Exception::class) | |
fun writePersonAndReadById() = runBlocking { | |
val person = createTestPerson() | |
val id = personDao.insert(person) | |
val retrievedPerson = personDao.getPersonById(id) | |
assertThat(person, equalTo(retrievedPerson)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment