F
F
foonfyrick2021-02-01 13:23:43
android studio
foonfyrick, 2021-02-01 13:23:43

How to test LiveData?

LiveData always returns an empty sheet

@Test
    fun insertHuman(){
        val human =Human(first_name = "Test",last_name = "Test",age = "11",job = "Test")
        db.takeDao().insertHuman(human)
        var list:List<Human> = ArrayList<Human>()
        db.takeDao().getPeople().observeForever{
            list=it
        }
        runBlocking { delay(2000L) }
        assertEquals(1,list.size)
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question