Search code examples
androidunit-testingandroid-jetpack-composedrawable

How to test Drawable in Jetpack Compose


I have a Box inside which I am adding image with drawable content. How can I write UI test for checking drawable is visible or not?


Solution

  • You can access the Semantic tree of a compose node, and determine the values of different things.

    Check this link for the specifics about how to access and display the Semantic tree in your logcat:

    https://developer.android.com/jetpack/compose/testing#finders

    You will use something like this:

    composeTestRule.onNode(<<SemanticsMatcher>>, useUnmergedTree = false): SemanticsNodeInteraction

    then:

    composeTestRule.onRoot().printToLog("TAG")

    to print the contents to your logcat