'Problem retrieving List out of the Flow while testing room database in android

I'm trying to test the insert operation in my room database. I have written the following code.

@Test
fun test() = runTest {
  val testString = "hello"
  dao.insert(testString)
  
  val allStrings = dao.getAllStrings()
  assertThat(allStrings).contains(testString)
}

The problem is dao.getAllStrings() returns a flow i.e. Flow<List<String>> so assertThat function written here does not work. Does anyone know how to efficiently handle the Flow here and get the List<String> out from that so that I can apply the assertThat function. Thanks in advance :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source