Skip to content

Commit cdbfdc8

Browse files
authored
Merge pull request #1104 from android/update-readme-for-testing
Update README.md to include more details about testing
2 parents 047ce5b + d711a1a commit cdbfdc8

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The app is currently in development. The `prodRelease` variant is [available on
2222
**Now in Android** displays content from the
2323
[Now in Android](https://developer.android.com/series/now-in-android) series. Users can browse for
2424
links to recent videos, articles and other content. Users can also follow topics they are interested
25-
in.
25+
in, and be notified when new content is published which matches interests they are following.
2626

2727
## Screenshots
2828

@@ -109,12 +109,42 @@ Examples:
109109
manipulate the state of the `Test` repository and verify the resulting behavior, instead of
110110
checking that specific repository methods were called.
111111

112-
## Screenshot tests
112+
To run the tests execute the following gradle tasks:
113+
114+
- `testDemoDebug` run all local tests against the `demoDebug` variant.
115+
- `connectedDemoDebugAndroidTest` run all instrumented tests against the `demoDebug` variant.
113116

114-
**Now In Android** uses [Roborazzi](https://github.com/takahirom/roborazzi) to do screenshot tests
115-
of certain screens and components. To run these tests, run the `verifyRoborazziDemoDebug` or
116-
`recordRoborazziDemoDebug` tasks. Note that screenshots are recorded on CI, using Linux, and other
117-
platforms might generate slightly different images, making the tests fail.
117+
**Note:** You should not run `./gradlew test` or `./gradlew connectedAndroidTest` as this will execute
118+
tests against _all_ build variants which is both unecessary and will result in failures as only the
119+
`demoDebug` variant is supported. No other variants have any tests (although this might change in future).
120+
121+
## Screenshot tests
122+
A screenshot test takes a screenshot of a screen or a UI component within the app, and compares it
123+
with a previously recorded screenshot which is known to be rendered correctly.
124+
125+
For example, Now in Android has [screenshot tests](https://github.com/android/nowinandroid/blob/main/app/src/testDemoDebug/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppScreenSizesScreenshotTests.kt)
126+
to verify that the navigation is displayed correctly on different screen sizes
127+
([known correct screenshots](https://github.com/android/nowinandroid/tree/main/app/src/testDemoDebug/screenshots)).
128+
129+
Now In Android uses [Roborazzi](https://github.com/takahirom/roborazzi) to run screenshot tests
130+
of certain screens and UI components. When working with screenshot tests the following gradle tasks are useful:
131+
132+
- `verifyRoborazziDemoDebug` run all screenshot tests, verifying the screenshots against the known
133+
correct screenshots.
134+
- `recordRoborazziDemoDebug` record new "known correct" screenshots. Use this command when you have
135+
made changes to the UI and manually verified that they are rendered correctly. Screenshots will be
136+
stored in `modulename/src/test/screenshots`.
137+
- `compareRoborazziDemoDebug` create comparison images between failed tests and the known correct
138+
images. These can also be found in `modulename/src/test/screenshots`.
139+
140+
**Note:** The known correct screenshots stored in this repository are recorded on CI using Linux. Other
141+
platforms may (and probably will) generate slightly different images, making the screenshot tests fail.
142+
When working on a non-Linux platform, a workaround to this is to run `recordRoborazziDemoDebug` on the
143+
`main` branch before starting work. After making changes, `verifyRoborazziDemoDebug` will identify only
144+
legitimate changes.
145+
146+
For more information about screenshot testing
147+
[check out this talk](https://www.droidcon.com/2023/11/15/easy-screenshot-testing-with-compose/).
118148

119149
# UI
120150
The app was designed using [Material 3 guidelines](https://m3.material.io/). Learn more about the design process and

0 commit comments

Comments
 (0)