【问题标题】:Jetpack Compose Testing: Assert specific image is setJetpack Compose 测试:断言特定图像已设置
【发布时间】:2021-10-10 05:05:52
【问题描述】:

我有一个Image,如下所示:

Image(
    bitmap = ImageBitmap.imageResource(id = R.drawable.testimage),
    contentDescription = null, // Only decorative image
    contentScale = ContentScale.FillWidth,
    modifier = Modifier
        .requiredHeightIn(max = 250.dp)
        .fillMaxWidth()
        .semantics { testTag = "MyTestTag" },
)

在仪器测试期间,我想确保设置了正确的可绘制对象。我没有在SemanticsProperties 之类的类中找到任何可以实现这一点的方法来编写自定义匹配器。有人可以帮忙吗?

【问题讨论】:

    标签: android kotlin android-jetpack android-jetpack-compose


    【解决方案1】:

    你可以用浓缩咖啡来做这个

     Espresso.onView(withId(R.drawable.testimage)).check(matches(isDisplayed()))
    

    https://developer.android.com/jetpack/compose/testing#espresso-interop

    语义显然不知道显示的是什么图像。

    【讨论】:

    • 你不能使用 espresso 来断言可组合的视图
    猜你喜欢
    • 2022-08-09
    • 1970-01-01
    • 2022-09-29
    • 2022-09-29
    • 2021-12-19
    • 2022-11-10
    • 2022-07-31
    • 2023-02-11
    • 1970-01-01
    相关资源
    最近更新 更多