【问题标题】:Android Jetpack Compose Robolectric createComposeRule java.lang.AbstractMethodErrorAndroid Jetpack Compose Robolectric createComposeRule java.lang.AbstractMethodError
【发布时间】:2022-10-25 18:52:47
【问题描述】:

我正在尝试使用 Robolectric 测试作曲。我创建了一个示例测试:

@RunWith(RobolectricTestRunner::class)
class ProductDescriptionComposeTest {

    @get:Rule
    val composeTestRule = createComposeRule()

    @Test
    fun testShowMoreText() {

    }
}

并添加到build.gradle

testImplementation 'junit:junit:4.13.2'
testImplementation "org.robolectric:robolectric:4.8.1"
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'androidx.compose.ui:ui-test-junit4:1.2.1'
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.2.1'

当我运行它时,我得到:

java.lang.AbstractMethodError: Receiver class androidx.compose.ui.test.TestMonotonicFrameClock does not define or inherit an implementation of the resolved method 'abstract kotlin.coroutines.CoroutineContext$Key getKey()' of interface kotlin.coroutines.CoroutineContext$Element.
at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:33)
at kotlin.coroutines.CoroutineContext$plus$1.invoke(CoroutineContext.kt:32)

在线:

val composeTestRule = createComposeRule()

我试图搜索,但所有示例代码都包含相同的并且可以工作

【问题讨论】:

    标签: android android-jetpack-compose robolectric


    【解决方案1】:

    我遇到了同样的错误,因为我在包含主要的 Compose 依赖项时犯了一个错误。

    我错误地有:

    testImplementation "androidx.compose.ui:ui:$compose_version"
    

    而我应该有

    implementation "androidx.compose.ui:ui:$compose_version"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-04
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 1970-01-01
      • 2022-07-16
      相关资源
      最近更新 更多