'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 1:[1]

Since I just ran into the same problem: The SemanticsTree seems to appear only when you run your tests in Debug Mode

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Robert Schröder