https://kotlinlang.org logo
#compose
Title
# compose
n

Neil

01/07/2022, 4:58 PM
Hi all, I want to test that my composables look correct so I want to check colour, spacing, font size etc. I’ve seen some references in the compose source code to Screenshot tests that use AndroidXScreenshotTestRule. Can’t find much information on this though. Does anyone know anything about these tests, like what dependencies are needed and how to set them up?
m

mattinger

01/07/2022, 6:07 PM
You would need the controls to have semantic properties attached to them. For instance, we have a “tone” parameter that controls the color of our buttons. We add that as a semantic property, and check that in our tests. I’m not sure of the full exhaustive list of semantic properties available, but you can use the composeTestRule to print the semantic tree:
Copy code
composeTestRule
                .onRoot()
                .printToString()
that should let you see what semantics are available.
You can use the “.semantics” modifier to add your own.
n

Neil

01/07/2022, 6:29 PM
@mattinger thanks I’ll take a look at Semantics some more. Still curious about the Screenshot tests though 🤔 https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]otlin/androidx/compose/material3/RadioButtonScreenshotTest.kt