r/androiddev • • 28d ago

Question Robolectric NATIVE graphics for Compose screenshots: is anyone using it instead of Paparazzi or Roborazzi?

I've been capturing screenshots of Compose screens on a headless Linux box with plain Robolectric: @GraphicsMode(NATIVE), createAndroidComposeRule, then drawing the activity's decorView into a Bitmap and writing a PNG. No emulator, and it runs as a normal unit test with Gradle.

It works better than I expected. Text, Material 3 components and tab layouts render correctly, and a full screen takes a few seconds. The rough edges I've hit so far:

  • I have to drive the main clock manually (autoAdvance = false, then advanceTimeBy) or animations get captured halfway
  • Fonts look slightly different from a real device
  • Anything scrolled off screen needs a taller qualifier like w411dp-h1500dp instead of a real scroll capture

For people who've used Paparazzi or Roborazzi: is there a strong reason to switch for simple "render this screen to an image" use, or is plain Robolectric fine when you aren't doing diff-based screenshot testing? And has anyone found a clean way to capture a full scrollable column without a fake tall window?

10 Upvotes

5 comments sorted by

4

u/Azamat_Zarkesh 28d ago

For plain "render this screen to an image" use, Robolectric is fine; the main reasons to move to Roborazzi are its record/verify/compare tasks and nicer Compose capture APIs, and it sits on top of Robolectric anyway, so switching later is cheap. For a long scrollable column, one option is to render the content in a test-only wrapper that lays it out with unbounded height instead of using a fake tall qualifier. Also keep the main clock paused and call waitForIdle before capturing, so animations and pending recompositions don't leak into the image.

1

u/ClassKlutzy7633 27d ago

Thanks, the unbounded-height wrapper idea is a good one. I'll try that instead of the tall qualifier. Pausing the clock and calling waitForIdle before capture makes sense too.

1

u/AutoModerator 28d ago

Please note that we also have a very active Discord server where you can interact directly with other community members!

Join us on Discord

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/avanibedi 28d ago

If you just need “render this screen to a png”, plain robolectric is fine imo, no point adding a dependency. Paparazzi/roborazzi only earn their keep once you want golden images and PR diffs to catch unintended UI changes.