1

所以我有一个标题中提到的错误。由于我是测试新手,我决定按照教程来测试我的代码。

我的目标是查看列表中是否有项目。

这是我的代码:

 @Test
    fun WriteAndReadPlant()=runBlocking(){


        val imageUrl = URL(url)
        var options: BitmapFactory.Options? = null
        options = BitmapFactory.Options()
        options.inSampleSize = 3
        val bitmap = BitmapFactory.decodeFile(imageUrl.toString(),
                options)
        val stream = ByteArrayOutputStream()

        bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream)
        val byte_arr: ByteArray = stream.toByteArray()

        val plant = Plant(Math.random().toLong(),"Vera",byte_arr,"Aloe","2 times a week ,Water more in summer","Is not safe to digest for pets")
        dao.insertPlant(plant);

        val plants =dao.getAll() // the data contains in Flow<List<>> type array
        assertThat(plants, contains(plant)).isTrue()// It shows that assertThat method has an error.


    }

也许我使用了错误的方法来测试 Flow<List> 类型的数组。我试图找到一个与我试图实现的目标或解决方案相似的教程,但我没有找到。

4

0 回答 0