You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Compose BOM 2023.08.00后LazyColumn节点残留致Instrumented测试失败求助

LazyColumn测试节点重复问题求助

环境信息

  • Jetpack Compose版本:Compose BOM 2023.08.00
  • 使用的Compose组件:Foundation、Material、Animations、LiveData、UI Tooling、ViewModel
  • Kotlin版本:1.9.10

复现步骤

  1. 向LazyColumn添加条目并将底部条目向下推送时,会出现条目节点重复的情况,导致Instrumented测试失败——因为存在多个相同测试标签的节点。该问题在Compose BOM 2023.08.00版本前并未出现。
  2. Lazy列表条目变化后,旧节点会残留在层级结构中:一种是带有可见参数的真实按钮节点,另一种是原位置的无参数“幽灵节点”。

问题求助

有没有开发者碰到过这类问题?如果有,有没有办法在Compose Instrumented测试中只定位可见节点,避免因节点重复导致的模糊异常?

示例代码

LazyColumn(
    modifier = Modifier.testTag(COMMUTE_ITEM_LIST),
    state = state
) {
    item { Spacer(modifier= Modifier.height(topPaddingDp)) }
    items(itemViews.size, key = { itemViews[it].uniqueId }) { index ->
        AnimateItemPlacements {
            CommuteItemRow(
                modifier = Modifier,
                itemViews = itemViews,
                index = index,
                onRemoveItemAtIndex = onRemoveItemAtIndex,
                onEditItemAtIndex = onEditItemAtIndex,
                onItemMoved = onItemMoved
            )
        }
    }

    item {
        AddItemButton(
            modifier = Modifier,
            index = itemViews.size,
            onAddItemAtIndex = onAddItemAtIndex
        )
    }
    item {
        Spacer(Modifier.height(bottomPaddingDp))
    }
}

补充说明

  • 已在Google官方问题追踪器提交该问题
  • 有两张相关截图,分别展示真实可见节点和原位置的“幽灵节点”

内容的提问来源于stack exchange,提问作者Sean Blahovici

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 03:53:22