androidandroid-jetpack-composeandroid-jetpack-compose-testing

Printing Compose Semantics Tree to the Log


I am following Testing in Jetpack Compose Codelab but I am unable to print the Semantics tree using the printToLog function on a node. I am using this code inside the androidTest package.

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")
        
            ....
    }

I have checked my LogCat with both Debug and Verbose filtering using "currentLabelExists" tag but the Semantics Tree is not printing on the log.

Any ideas on what I might be missing out.


Solution

  • I can see the semantics tree.
    Check if Android Studio Logcat has "No Filters"

    Filter options

    Edit
    It seems to be a bug as I can sometimes see the logs even if I select "Show only selected application".