top of page
< Back

Android Screenshot Testing on Autopilot

Status: Accepted

Screenshot testing is an essential but often tedious process in Android development. Traditional
approaches require developers to manually write and maintain screenshot tests, increasing development
time and maintenance overhead.

In this talk, I will demonstrate how to automate screenshot testing using Jetpack Compose previews by
leveraging Kotlin Symbol Processing (KSP), Paparazzi, and a custom Gradle plugin. This approach allows
developers to generate screenshot tests dynamically at compile time without modifying their existing
code. Additionally, I will explain how the Gradle plugin ensures the correct configuration before KSP
execution, enabling a seamless integration into any project.

One of the key challenges I tackled was managing source sets—since @Preview functions reside in the
main source set, the generated tests must also be part of it. I will explain how I solved this by defining a
new test source set within the main source set, allowing the generated tests to execute properly.

Furthermore, I will discuss how this method can be extended beyond @Preview annotations using
custom annotations and how unit testing KSP can help reduce maintenance overhead, given that the
generated code structure remains stable.

This session is ideal for Android developers looking to streamline their UI testing process, reduce
maintenance effort, and ensure consistent screenshot outputs with Compose previews.

Key Takeaways:
1. Automate screenshot tests using Jetpack Compose previews without modifying existing code.
2. Leverage KSP and a Gradle plugin to dynamically generate and execute tests at compile time.
3. Manage source set challenges by defining a test source set within the main source set.
4. Discuss how unit testing KSP can minimize maintenance costs due to its stable generated code
structure.
5. Extend the approach beyond @Preview with custom annotations.

Keywords:
Jetpack Compose, Kotlin Symbol Processing (KSP), Screenshot Testing, Paparazzi, UI Testing, Gradle Plugin,
Automation, Preview Annotation

Speakers

Cagdas Caglak

Lead Software Engineer at JPMorgan Chase & Co.

bottom of page