首页 > 解决方案 > 将 Compose 语义树打印到日志

问题描述

我正在Jetpack Compose Codelab 中进行测试,但我无法使用节点上的函数打印语义树。printToLog我在androidTest包内使用此代码。

import androidx.compose.ui.test.printToLog 

...

    //testing function
    @Test
    fun rallyTopAppBarTest() {
    
        val allScreen = RallyScreen.values().toList()
        testRule.setContent {
            //the component be tested in isolation goes here
            RallyTopAppBar(
                allScreens = allScreen,
                onTabSelected = {},
                currentScreen = RallyScreen.Accounts
            )
        }
        
        testRule.onRoot().printToLog("currentLabelExists")
        
            ....
    }

我已经使用标签检查了我的 LogCat调试详细过滤,"currentLabelExists"但语义树没有在日志上打印。

关于我可能会错过的任何想法。

标签: androidandroid-jetpack-composeandroid-jetpack-compose-testing

解决方案


我可以看到语义树。
检查 Android Studio Logcat 是否有“无过滤器”

过滤器选项

编辑
这似乎是一个错误,因为即使我选择“仅显示选定的应用程序”,我有时也可以看到日志。


推荐阅读