A Compose project tends to collect a lot of @Preview functions that describe exactly how each screen should look, and usually nothing checks them. Screenshot tests would, but the usual setup means writing a test class, listing every screen in it, and remembering to add new ones. Coverage tends to stop at the screens someone thought of first.

So I made Mugshot. It started as a fork of Paparazzi and has grown into its own library. You put an annotation on a preview:

@Mugshot @Preview @Composable internal fun ProfileScreenPreview() { AppTheme { ProfileScreen(state = sampleProfile) } } 

Then run ./gradlew recordMugshot once and commit the images. From then on verifyMugshot fails the build when that screen changes. A KSP processor generates the test, so there's no test class to write and no list of screens to keep in sync. Add a preview and it's covered.

The output

Performance. I benchmarked it against Paparazzi and Google's Compose Preview Screenshot Testing on a generated app with 30 modules and 299 previews, each rendered in 24 configurations (7,176 screenshots per tool), on a MacBook Pro M5 Pro:

Library Record Verify Verify, --max-workers=3 Golden images Mugshot 3.4.2 62 s 58 s 88 s 75 MB Paparazzi 2.0.0-alpha05 107 s 89 s 149 s 279 MB Compose Preview Screenshot Testing 0.0.1-alpha16 226 s out of memory 728 s 619 MB

The app, one branch per tool, the script and all raw results are public, so you can check or rerun it: https://github.com/TRazDev/screenshot-testing-benchmark

It also fits well with AI coding agents. Instead of driving an emulator and screenshotting every screen to check its own UI changes, an agent runs one Gradle task, reads which screens changed, and only looks at the diffs for those. On a redesign that's the difference between checking every screen and checking a few.

GitHub: https://github.com/TRazDev/Mugshot
KMP sample app: https://github.com/TRazDev/MugshotSampleKMP
On Maven Central as uk.co.fractalmotion.mugshot

I'd really like feedback, especially from anyone already using Paparazzi, Roborazzi or Google's tool

submitted by /u/Early-Principle-4325
[link] [comments]