Android 将LiveDataTestUtil与Kotest一起使用

Android 将LiveDataTestUtil与Kotest一起使用,android,android-livedata,android-architecture-components,kotest,Android,Android Livedata,Android Architecture Components,Kotest,我一直在阅读,我一直在努力找出如何在Kotest中尽可能地使用它进行测试。主要是因为(现在)Kotest不提供LiveData测试功能。是否有一种惯用的方法来测试事件(基于LiveData),即基于发布的util?我的解决方案是将以下内容添加到util中: @VisibleForTesting(otherwise = VisibleForTesting.NONE) infix fun <T, U : T> LiveData<Event<T>>.shouldBe

我一直在阅读,我一直在努力找出如何在Kotest中尽可能地使用它进行测试。主要是因为(现在)Kotest不提供LiveData测试功能。是否有一种惯用的方法来测试事件(基于LiveData),即基于发布的util?

我的解决方案是将以下内容添加到util中:

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
infix fun <T, U : T> LiveData<Event<T>>.shouldBeTriggered(
    expected: U
) {
    val value = this.getOrAwaitValue()
    value.getContentIfNotHandled() shouldBe expected
}
@VisibleForTesting(否则=VisibleForTesting.NONE)
infix fun LiveData.shouldBeTriggered(
预期:美国
) {
val value=this.getOrAwaitValue()
应为value.getContentIfNotHandled()
}
这样就可以使用
事件shouldbetriggeredwithvalue
作为测试