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?
CodePudding user response:
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
CodePudding user response:
I don't think we can do that in the UI test, I have written a story in a medium that discusses a little about testing UI in jetpack compose.
But I have found another approach that for me personally is better than UI testing using espresso, you can read more about it in my medium story it is a snapshot test. you can use this library to do a snapshot test to test your UI.