Last active
December 16, 2018 10:25
-
-
Save alediaferia/21127133c13bba364c1679f73065c81d to your computer and use it in GitHub Desktop.
A non-working test with LiveData
This file contains hidden or 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 PostDaoReadWriteTest { | |
private lateinit var postDao: PostDao | |
private lateinit var db: TestDatabase | |
@Before | |
fun createDb() { | |
val context = ApplicationProvider.getApplicationContext<Context>() | |
db = Room.inMemoryDatabaseBuilder( | |
context, TestDatabase::class.java).build() | |
postDao = db.getPostDao() | |
} | |
@After | |
@Throws(IOException::class) | |
fun closeDb() { | |
db.close() | |
} | |
@Test | |
@Throws(Exception::class) | |
fun writePostAndReadInList() { | |
assertEquals(0, postDao.getAll().value?.size) | |
val post = TestUtil.createPost(id=42) | |
postDao.insert(post) | |
assertEquals(1, posttDao.getAll().value?.size) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment