Skip to content

feat: add screenshot testing to compose snippets#958

Open
prateekbatra-g wants to merge 2 commits into
adaptive-layoutsfrom
adaptive-layouts-tests
Open

feat: add screenshot testing to compose snippets#958
prateekbatra-g wants to merge 2 commits into
adaptive-layoutsfrom
adaptive-layouts-tests

Conversation

@prateekbatra-g

Copy link
Copy Markdown
Contributor
  • 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

@prateekbatra-g prateekbatra-g self-assigned this Jun 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@prateekbatra-g prateekbatra-g force-pushed the adaptive-layouts-tests branch from 3749e65 to 1bab3a5 Compare June 18, 2026 05:37
@prateekbatra-g prateekbatra-g requested a review from telpirion June 18, 2026 05:37
@prateekbatra-g prateekbatra-g force-pushed the adaptive-layouts-tests branch from 1bab3a5 to 396aa87 Compare June 18, 2026 06:39
@prateekbatra-g prateekbatra-g marked this pull request as ready for review June 18, 2026 12:05
@prateekbatra-g prateekbatra-g requested review from a team, kkuan2011 and yrezgui as code owners June 18, 2026 12:05
@prateekbatra-g prateekbatra-g requested review from simona-anomis and removed request for a team June 18, 2026 12:05
Comment thread gradle/libs.versions.toml Outdated
prateekbatra-g and others added 2 commits June 23, 2026 09:49
* 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
@prateekbatra-g prateekbatra-g force-pushed the adaptive-layouts-tests branch from 396aa87 to bab8562 Compare June 23, 2026 04:20

@kkuan2011 kkuan2011 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread gradle/libs.versions.toml
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"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you put in alphabetical order?

import org.junit.Rule
import org.junit.Test

class MyFeedTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to provide any input on what type of device to take the screenshots on?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does make sense. Ideally we would take screenshots on:

  1. Phone (Pixel)
  2. Foldable (Pixel Fold)
  3. Tablet (Pixel Tablet OR Samsung Galaxy)
  4. Connected display (25" monitor)

@telpirion telpirion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does make sense. Ideally we would take screenshots on:

  1. Phone (Pixel)
  2. Foldable (Pixel Fold)
  3. Tablet (Pixel Tablet OR Samsung Galaxy)
  4. Connected display (25" monitor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants