You build a clean UI, test it on your emulator, and everything looks solid. But once QA or users get their hands on it, layout bugs pop up — text overflowing, views misaligned, odd paddings. It happens more often than we like to admit.
That’s where the Paparazzi Testing Library proves its worth. It’s a powerful snapshot testing tool that helps you catch UI issues early — without spinning up an emulator or device. It’s fast, reliable, and runs directly on the JVM.
Here’s what makes Paparazzi a smart addition to your toolkit — and how to get started using it today.
What Is the Paparazzi Testing Library?
The Paparazzi Testing Library is a screenshot testing tool developed by Cash App (Square). It renders Android views directly on your local JVM, meaning no more waiting for Gradle to launch an emulator. You write tests that take UI snapshots and compare them to previously approved images. If something changes, you’ll know — instantly.
It’s like version control for your UI.
Why Snapshot Testing Matters
Snapshot testing is about locking down the visual representation of your UI. When your layout changes unexpectedly — due to a rogue commit, a bumped font size, or some sneaky theme refactor — snapshot tests fail, and you get a diff of what changed.
This catches visual regressions without needing a manual check.
“But isn’t this what Espresso is for?”
Nope. Espresso is great for behavior tests — clicks, scrolls, text input — but it’s not built to capture static snapshots or catch pixel-level layout issues. That’s exactly what Paparazzi is made for.
In essence:
- Espresso = “Does the app behave correctly when a user interacts with it?”
- Paparazzi = “Does the app look correct across different states and configurations?”
They complement each other, addressing different aspects of UI testing.
Getting Started with Paparazzi
First, you need to add the dependency to your build.gradle.kts:
// build.gradle.kts (module)
dependencies {
testImplementation("app.cash.paparazzi:paparazzi:1.3.0")
}Then, make sure your project uses AGP 7.0+. Paparazzi integrates seamlessly with Compose and traditional XML views.
Your First Snapshot Test
Let’s say you have a simple composable:
@Composable
fun GreetingCard(name: String) {
Surface(color = Color.White) {
Text(
text = "Hello, $name..!",
modifier = Modifier.padding(16.dp),
fontSize = 18.sp
)
}
}Here’s how you’d test it with Paparazzi:
class GreetingCardTest {
@get:Rule
val paparazzi = Paparazzi()
@Test
fun greetingCardSnapshot() {
paparazzi.snapshot {
GreetingCard(name = "Shakuntala Devi")
}
}
}Run the test, and boom — you get a PNG snapshot of the rendered composable. If you change the layout later and rerun the test, Paparazzi compares the new image to the baseline. Any difference? You’ll get a visual diff and a failing test.
Reviewing Changes
Let’s say your team modifies the GreetingCard to bump the padding. When you commit, the snapshot test will fail (as expected). Here’s the best part: Paparazzi gives you a side-by-side diff view of the change.
If the change is intentional, just approve the new snapshot. If not, you just caught a bug before it shipped.
Tips and Best Practices
Here are a few lessons I’ve learned the hard way:
- Use stable fonts and themes: Dynamic styling can trigger unnecessary diffs.
- Avoid timestamps or dynamic content in your snapshots.
- Organize snapshots by feature to keep your test suite tidy.
- Pair with pull requests: Have your CI pipeline run snapshot tests on every PR.
How It Works Under the Hood
Paparazzi uses RenderScript and Skia to render Android views headlessly. It builds your composables or views in a JVM environment and captures the exact pixels they produce.
No emulator, no instrumentation, no flakiness.
When Not to Use Paparazzi
Paparazzi is not meant to test animations, gestures, or interactive flows. It shines in static UI verification. If your test involves user interaction, Espresso or Compose UI testing is your better bet.
Conclusion
If you’re serious about UI quality, the Paparazzi Testing Library is a must-have. It’s fast, consistent, and ridiculously easy to use once you get the hang of it. Plus, catching layout regressions early saves your team countless hours of QA churn and bug fixes.
Give it a try on your next UI feature. You’ll wonder how you ever lived without it.
TL;DR
- Paparazzi = snapshot testing for Android UIs on the JVM
- No emulator needed
- Great for catching unexpected layout changes
- Easy to set up and integrates with Compose
- Ideal for static UI components
