feat: add screenshot testing to compose snippets#958
Conversation
There was a problem hiding this comment.
Code Review
This pull request configures screenshot testing for the project by adding the screenshot plugin, enabling the experimental screenshot test property, and adding the necessary dependencies. It also introduces a new instrumented test for MyFeed and adds screenshot tests for both MyFeed and GridExample. The feedback suggests fixing a duplicate package segment and directory nesting in MyFeedScreenShotTest.kt, and refactoring GridExampleTest.kt to define the preview functions as top-level functions instead of wrapping them in a class to align with Jetpack Compose idioms.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
3749e65 to
1bab3a5
Compare
1bab3a5 to
396aa87
Compare
* Enable experimental screenshot testing in Gradle configuration and `gradle.properties` * Add screenshot testing plugin and validation dependencies * Implement screenshot tests for grid and adaptive layout snippets * Add instrumentation test for `MyFeed` snippet * Include initial screenshot reference images for validation tests
396aa87 to
bab8562
Compare
kkuan2011
left a comment
There was a problem hiding this comment.
Thank you Prateek for adding tests! Could you get approval from a teammate before Yacine/I approve? Do you want to ping Jose to see if he'd like to review too?
| glance-preview = { group = "androidx.glance", name = "glance-preview", version.ref = "androidx-glance-appwidget" } | ||
| glance-appwidget-preview = { group = "androidx.glance", name = "glance-appwidget-preview", version.ref = "androidx-glance-appwidget" } | ||
| screenshot-validation-api = { group = "com.android.tools.screenshot", name = "screenshot-validation-api", version.ref = "screenshotValidationApi" } | ||
| androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling"} |
There was a problem hiding this comment.
nit: can you put in alphabetical order?
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class MyFeedTest { |
There was a problem hiding this comment.
do we need to change the github action so that the tests are run for every PR? otherwise people may not realize that a code change breaks the test
There was a problem hiding this comment.
That makes sense to me. @kkuan2011 should we add a workflow file to this PR? That would allow us to check the workflow along with this test.
| @Preview | ||
| @PreviewTest | ||
| @Composable | ||
| fun GridExamplePreviewTest() { |
There was a problem hiding this comment.
Do we need to provide any input on what type of device to take the screenshots on?
There was a problem hiding this comment.
That does make sense. Ideally we would take screenshots on:
- Phone (Pixel)
- Foldable (Pixel Fold)
- Tablet (Pixel Tablet OR Samsung Galaxy)
- Connected display (25" monitor)
telpirion
left a comment
There was a problem hiding this comment.
Thank you SO much @prateekbatra-g for putting this together. I think this will be immeasurably helpful in maintaining quality in our samples.
One question @kkuan2011 : should we migrate these tests to a dedicated "adaptive" module, given other ongoing conversations?
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class MyFeedTest { |
There was a problem hiding this comment.
That makes sense to me. @kkuan2011 should we add a workflow file to this PR? That would allow us to check the workflow along with this test.
| @Preview | ||
| @PreviewTest | ||
| @Composable | ||
| fun GridExamplePreviewTest() { |
There was a problem hiding this comment.
That does make sense. Ideally we would take screenshots on:
- Phone (Pixel)
- Foldable (Pixel Fold)
- Tablet (Pixel Tablet OR Samsung Galaxy)
- Connected display (25" monitor)
gradle.propertiesMyFeedsnippet