<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Artsiom Seliuzhytski on Medium]]></title>
        <description><![CDATA[Stories by Artsiom Seliuzhytski on Medium]]></description>
        <link>https://medium.com/@traz.developer?source=rss-592d61341845------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vg2j-YoC46FQ-WteVGaNAA.jpeg</url>
            <title>Stories by Artsiom Seliuzhytski on Medium</title>
            <link>https://medium.com/@traz.developer?source=rss-592d61341845------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:36:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@traz.developer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mugshot, Paparazzi and Compose Preview Screenshot Testing on the same 7,176 screenshots]]></title>
            <link>https://medium.com/@traz.developer/mugshot-paparazzi-and-compose-preview-screenshot-testing-on-the-same-7-176-screenshots-3292c03694f1?source=rss-592d61341845------2</link>
            <guid isPermaLink="false">https://medium.com/p/3292c03694f1</guid>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Artsiom Seliuzhytski]]></dc:creator>
            <pubDate>Tue, 22 Sep 2026 07:36:01 GMT</pubDate>
            <atom:updated>2026-09-22T07:36:01.383Z</atom:updated>
            <content:encoded><![CDATA[<h4>Record and verify times, memory, disk and the code each tool needs, measured on one app</h4><p>I maintain Mugshot, so treat anything I say about it with the suspicion that deserves. What I can do is make the comparison easy to check. The app, the setup for each tool, the benchmark script and the raw results are all in <a href="https://github.com/TRazDev/screenshot-testing-benchmark">a public repository</a>, and every number below comes from running it.</p><p>The three tools:</p><ul><li><a href="https://github.com/TRazDev/Mugshot">Mugshot</a> 3.4.2, which generates screenshot tests from annotated previews</li><li><a href="https://github.com/cashapp/paparazzi">Paparazzi</a> 2.0.0-alpha05, the library Mugshot was forked from, where you write the tests</li><li><a href="https://developer.android.com/studio/preview/compose-screenshot-testing">Compose Preview Screenshot Testing</a> 0.0.1-alpha16, Google’s Gradle plugin that renders @PreviewTest functions</li></ul><p>Two of them are alphas. I used the latest release of each.</p><p>All three do the same job. They render your Compose screens without a device and fail when one changes. That’s what lets a team cover every state of every screen and see the whole app during a redesign, and it puts UI changes in front of reviewers as images. What differs is how cheap the check is to run and how much code it takes to keep up, which is what this measures.</p><h3>The app</h3><p>The app is generated, so each tool gets exactly the same screens. It has 30 Gradle modules, a design system plus 29 feature modules, holding 293 screens and 6 component catalogues built from Material 3. Each has a @Preview, for 299 previews.</p><p>Every preview is screenshotted in the same 24 configurations: a Pixel 10, a Pixel Fold, a Pixel Tablet and the Pixel 10 in landscape, each in light and dark, at font scales of 1, 1.5 and 2. That’s 7,176 screenshots per tool.</p><p>The repository’s main branch is the app with no screenshot testing. Each tool has its own branch, so git diff main..mugshot shows exactly what Mugshot needed, and the same for the others.</p><h3>What each tool needs</h3><p>All three reuse the app’s existing preview functions. They differ in where the list of screens and configurations lives.</p><p>With Mugshot, it lives on the previews. Each one gets two annotations, and a KSP processor generates the test:</p><pre>@Mugshot<br>@MugshotMatrix<br>@Preview<br>@Composable<br>internal fun OrdersBooking1ScreenPreview() {<br>    OrdersBooking1Screen()<br>}</pre><p>With Paparazzi, each module has a test class. The class lists the module’s previews in an enum and uses TestParameterInjector to run every preview on every device, theme and font scale:</p><pre>@RunWith(TestParameterInjector::class)<br>class ScreenshotTest(<br>    @TestParameter private val preview: Preview,<br>    @TestParameter private val device: Device,<br>    @TestParameter private val nightMode: Appearance,<br>    @TestParameter private val fontScale: FontScale,<br>) {<br>    @get:Rule<br>    val paparazzi = Paparazzi(<br>        deviceConfig = device.config.copy(nightMode = nightMode.mode, fontScale = fontScale.scale),<br>        theme = &quot;android:Theme.Material.Light.NoActionBar&quot;,<br>    )<br> <br>    @Test<br>    fun snapshot() {<br>        paparazzi.snapshot { preview.content() }<br>    }<br> <br>    enum class Preview(val content: @Composable () -&gt; Unit) {<br>        OrdersContact0Screen({ OrdersContact0ScreenPreview() }),<br>        OrdersBooking1Screen({ OrdersBooking1ScreenPreview() }),<br>        // one line per preview in the module<br>    }<br> <br>    // plus enums for the four devices, two themes and three font scales<br>}</pre><p>With Compose Preview Screenshot Testing, each module has a file in the screenshotTest source set. It declares a multi-preview annotation with the 24 configurations, and a @PreviewTest function per preview that calls the existing one:</p><pre>@Preview(name = &quot;Phone_Light_Font100&quot;, device = &quot;spec:width=411dp,height=923dp,dpi=420&quot;, uiMode = Configuration.UI_MODE_NIGHT_NO, fontScale = 1f)<br>// ... 23 more<br>annotation class ScreenshotMatrix<br> <br>@PreviewTest<br>@ScreenshotMatrix<br>@Composable<br>fun OrdersBooking1ScreenPreviewScreenshot() {<br>    OrdersBooking1ScreenPreview()<br>}</pre><p>Counted from the diffs, ignoring blank lines:</p><figure><img alt="Table of lines each tool adds: Mugshot 62 lines of build configuration, no test code and 1,193 lines in app code, 1,255 in total; Paparazzi 61, 2,189 and 0, 2,250 in total; Compose Preview Screenshot Testing 123, 2,694 and 0, 2,817 in total" src="https://cdn-images-1.medium.com/max/1024/1*8vttD6ow8rxCh1NGj3CMmw.png" /><figcaption>Lines each branch adds to the same app, ignoring blank lines</figcaption></figure><p>The totals flatter Mugshot a little and hide something about Paparazzi. Most of Paparazzi’s lines are device and theme setup that I repeated in every module’s test class; a team would put that in one shared place and cut the count a lot. Once that setup exists, a new screen costs Paparazzi one line, the fewest of the three. Mugshot’s cost is two annotations and their imports on each preview, and Compose Preview Screenshot Testing needs a four-line function per preview.</p><p>The number that matters to me more than the total is where a new screen has to be registered. With Mugshot, the annotation sits on the preview, so a screen and its screenshot test are added and deleted together. With the other two, someone has to remember to add the preview to a separate file, and a screen that nobody adds has no test and nothing to say so.</p><h3>The images aren’t the same size</h3><p>All three tools rendered the same layout, but not at the same resolution.</p><figure><img alt="The same Booking details screen in dark mode from each tool: Mugshot at 360 by 808 pixels (10 KB), Paparazzi at 445 by 1000 (33 KB) and Compose Preview Screenshot Testing at 1079 by 2423 (77 KB)" src="https://cdn-images-1.medium.com/max/1024/1*vr4MoOmM6VpEiR-P0ZAkTA.png" /><figcaption>The same screen from each tool</figcaption></figure><p>Mugshot renders the device at a third of its resolution by default. Paparazzi renders at full resolution and then shrinks the image so its longest side is 1,000 pixels. Compose Preview Screenshot Testing keeps the full resolution, 1079 × 2423 for a phone.</p><p>That affects both time and disk, so Mugshot ran twice: once with its defaults and once with downscale = 1, which renders at full resolution.</p><h3>Results with default settings</h3><p>Each tool recorded all 7,176 golden images once, then verified them three times, with the order of the tools rotating each round. Every timed build started with the Gradle daemon stopped and the build cache off, and forced only the screenshot tasks to run. Compilation happened beforehand and isn’t included.</p><p>All 7,176 screenshots passed on every run that finished, for every tool.</p><p>Mugshot at full resolution is slower than Paparazzi. Paparazzi shrinks its images to fit 1,000 pixels before comparing, so it compares about a sixth of the pixels per phone screenshot, and Mugshot at downscale = 1 compares all of them.</p><figure><img alt="Bar charts of wall-clock time with default settings. Record: Mugshot 62 s, Mugshot at full resolution 150 s, Paparazzi 107 s, Compose Preview Screenshot Testing 226 s. Verify: Mugshot 58 s, full resolution 149 s, Paparazzi 89 s, Compose Preview Screenshot Testing did not finish" src="https://cdn-images-1.medium.com/max/1024/1*nXsQxgPM6mUetJ41yDskRg.png" /><figcaption>Record and verify times with default settings</figcaption></figure><h3>Compose Preview Screenshot Testing ran out of memory</h3><p>The first attempt recorded screenshots for a few minutes and then stopped making progress. Its renderer processes had hit OutOfMemoryError: Java heap space, 347 screenshots had failed, and the rest sat in garbage collection. It was still running eight hours later when I stopped it.</p><p>With its default heap, recording even one module on its own failed: 66 of that module’s 336 screenshots errored out, with 16 OutOfMemoryErrors in the log. Google&#39;s documentation describes a Gradle property for this, android.compose.screenshot.maxHeapSize. At 2g the same module recorded every screenshot, in 51 seconds instead of 122, and its renderer processes used about 6.8 GB between them at their peak.</p><p>With the heap at 2 GB, the whole app recorded at default parallelism in 226 seconds. Verifying at default parallelism didn’t fit on this machine. Within three minutes free memory dropped from 71% to 32%, swap grew by a gigabyte, and the run was killed for lack of memory before it finished. Limited to three Gradle workers, it recorded and verified without trouble.</p><p>Anyone moving a large app to Compose Preview Screenshot Testing will probably need that property, and possibly fewer workers on CI. The first failure is worth knowing about too: the build didn’t fail when the renderer ran out of memory. It kept running and stopped making progress.</p><h3>Results with the same limits for everyone</h3><p>A 15-core machine is generous. GitHub’s standard Linux runners have 4 CPUs, and parallelism hides a lot of per-screenshot cost, so I ran every tool again with --max-workers=3, keeping the 2 GB heap for Compose Preview Screenshot Testing. It&#39;s also the only configuration in which all three finished both recording and verifying.</p><figure><img alt="Bar charts of wall-clock time with — max-workers=3. Record: Mugshot 88 s, Mugshot at full resolution 179 s, Paparazzi 205 s, Compose Preview Screenshot Testing 347 s. Verify: Mugshot 88 s, full resolution 215 s, Paparazzi 149 s, Compose Preview Screenshot Testing 728 s" src="https://cdn-images-1.medium.com/max/1024/1*ja8f1gdY11h_H9Vwbq0MWw.png" /><figcaption>Record and verify times with --max-workers=3</figcaption></figure><p>The gaps widen with fewer workers. Compose Preview Screenshot Testing took about twice as long to verify as to record, with the CPU mostly idle while it did. I haven’t dug into why.</p><h3>Disk</h3><figure><img alt="Bar chart of golden images on disk for 7,176 screenshots: Mugshot 75 MB, Mugshot at full resolution 237 MB, Paparazzi 279 MB, Compose Preview Screenshot Testing 619 MB" src="https://cdn-images-1.medium.com/max/1024/1*NkYtaV6JwZKvoxwWwdjMcQ.png" /><figcaption>Golden images on disk</figcaption></figure><figure><img alt="Table of golden images: Mugshot 360 by 808 WebP, 75 MB for all 7,176; Mugshot at full resolution 1080 by 2424 WebP, 237 MB; Paparazzi 445 by 1000 PNG, 279 MB; Compose Preview Screenshot Testing 1079 by 2423 PNG, 619 MB" src="https://cdn-images-1.medium.com/max/1024/1*sQgeE5kTRYAIzmTUPh0MFQ.png" /><figcaption>Golden image size and format for a phone screenshot, and the total for 7,176 images</figcaption></figure><p>Golden images usually live in git, often through Git LFS, so this is the size every clone and every CI checkout carries, and it grows with every re-record. At the same resolution, Mugshot’s WebP images take a little over a third of the space of Compose Preview Screenshot Testing’s PNGs.</p><h3>What the differences mean in practice</h3><p>The verify time is what everyone waits for. A check that takes a minute gets run before every push and after every refactor. A check that takes twelve minutes is more likely to be left to CI, where a broken screen turns up later.</p><p>That applies even more to AI coding agents doing UI work. An agent that can run the screenshot tests after each edit can check its own work across every screen, device and theme without starting an emulator, navigating the app and studying a screenshot of each screen. Often the output is enough: a list of which screens changed, or no failures at all. It only needs to open images for the screens that failed. The faster that loop runs, the more often the agent can afford to use it, and on a large redesign it’s the difference between checking every screen and checking a few.</p><p>Image size matters for the same reason. A reviewer scrolling through updated golden images, or an agent inspecting a failure, looks at one of these files for every changed screen. Most models charge for an image by its size in pixels, so a phone screenshot from Mugshot, at 360 × 808, costs an agent far less to look at than the 1079 × 2423 PNG from Compose Preview Screenshot Testing.</p><p>And where a screen gets registered decides whether new screens are tested at all. When an agent adds a screen with a preview and an annotation, the screen has a screenshot test. With the other two tools, the agent, or the person reviewing its work, also has to remember to add the preview to a separate test file.</p><h3>What this doesn’t tell you</h3><p>This is one app on one machine, a MacBook Pro with an M5 Pro and 24 GB of memory. The app is generated, so it’s regular in a way real apps aren’t, and it has no custom views, maps, animations or bitmaps.</p><p>It measures a full run of every screenshot. Day to day, Gradle skips the screenshot tasks of modules that didn’t change, so most runs are far smaller than this.</p><p>It doesn’t cover Roborazzi, which runs screenshot tests through Robolectric and deserves its own comparison. And it doesn’t measure the parts of each tool that aren’t about speed. Compose Preview Screenshot Testing is built into Android Studio and comes from Google. Paparazzi has years of production use and works with Android views as well as Compose.</p><h3>Running it yourself</h3><p>Everything is in <a href="https://github.com/TRazDev/screenshot-testing-benchmark">TRazDev/screenshot-testing-benchmark</a>. The README explains how to check out each branch and run tools/benchmark.py, which writes a CSV with one row per build. If you get different numbers on different hardware, I&#39;d like to hear about it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3292c03694f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My screenshot tests spent more time shrinking images than rendering them]]></title>
            <link>https://medium.com/@traz.developer/my-screenshot-tests-spent-more-time-shrinking-images-than-rendering-them-31e4d33900f2?source=rss-592d61341845------2</link>
            <guid isPermaLink="false">https://medium.com/p/31e4d33900f2</guid>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Artsiom Seliuzhytski]]></dc:creator>
            <pubDate>Sun, 20 Sep 2026 19:06:01 GMT</pubDate>
            <atom:updated>2026-09-20T19:06:01.377Z</atom:updated>
            <content:encoded><![CDATA[<h4>How rendering a smaller device made verification 27% faster and the golden images 45% smaller</h4><p>Mugshot is a screenshot testing library for Android. You put @Mugshot on a Compose preview, and it renders that screen on the JVM with layoutlib and fails the build when it changes. It started as a fork of Paparazzi and has grown into its own library since.</p><p>Speed matters more for screenshot tests than for most test suites, because their value comes from running them often. A team that can verify every screen in a minute runs the check on every pull request and before every refactor. An AI coding agent that can do the same runs it after every change it makes, instead of guessing whether the UI still looks right.</p><p>This post is about the biggest speedup so far. I found it by measuring where the time went, and the most expensive step turned out to be one that didn’t need to exist.</p><h3>The test project</h3><p>To measure a screenshot library you need a lot of screens, and ideally screens spread across modules the way a real app is. Open source apps were either too small or kept all their screenshots in one module, so I generated a project instead.</p><p>It has 30 Gradle modules: a design system and 29 feature modules that depend on it. Between them there are 299 @Preview functions built from Material 3 components, in six shapes (lists, detail screens, forms, dashboards, settings and empty states). Each preview carries @Mugshot and @MugshotMatrix, which ask for four devices, light and dark themes and three font scales. That&#39;s 24 images per preview and 7,176 in total.</p><p>There is no test code in the project. The Mugshot Gradle plugin generates the tests from the annotations, which also meant I could regenerate the whole thing at a different size whenever I wanted to check that a result held.</p><p>Everything below was measured on a 15-core Mac with Gradle 9.7.1 and AGP 9.3.2.</p><h3>Where the time went</h3><p>Rendering sounds like the expensive part, with comparing pixels against the golden image somewhere behind it. Rather than guess, I added timing around each phase of a screenshot, ran all 7,176 of them in verify mode, and added it up.</p><figure><img alt="Bar chart of the time to verify one screenshot, before the change: shrinking the rendered image 27%, rendering 20%, comparing pixels 18%, preparing the render session 17.5%, decoding the golden 4.5%, teardown and JUnit 3%" src="https://cdn-images-1.medium.com/max/1024/1*dcVnLrEY3LOwR7T1RNDfwQ.png" /><figcaption>Share of the time to verify one screenshot, before the change</figcaption></figure><p>Shrinking the rendered image was the most expensive step, at 27% of the time. Rendering itself was 20%.</p><p>The shrinking step is inherited from Paparazzi. Golden images there are capped at 1,000 pixels on their longest side, so the pipeline renders the device at its full resolution and then resamples the bitmap down to fit. A Pixel 10 renders at 1080 × 2424, so every phone screenshot in every test was drawn at that size and then scaled to about 445 × 1000.</p><h3>Rendering fewer pixels to begin with</h3><p>If the image ends up small anyway, there’s no reason to draw the big one first.</p><p>Android lays out a screen in density-independent pixels (dp). How many physical pixels a dp becomes depends on the screen density. A Pixel 10 at 420 dpi fits 411 dp across its 1,080 pixels. If you tell the renderer the screen is 360 pixels wide at 140 dpi, it is still 411 dp wide. The layout comes out the same, with a third of the pixels in each direction.</p><p>So instead of shrinking the screenshot, Mugshot now shrinks the device before rendering. Width, height, both dpi values and the density are all divided by the same factor:</p><pre>internal fun DeviceConfig.downscaledBy(factor: Float): DeviceConfig {<br>  if (factor &lt;= 1f) return this<br>  return copy(<br>    screenWidth = (screenWidth / factor).toInt().coerceAtLeast(1),<br>    screenHeight = (screenHeight / factor).toInt().coerceAtLeast(1),<br>    xdpi = (xdpi / factor).toInt().coerceAtLeast(1),<br>    ydpi = (ydpi / factor).toInt().coerceAtLeast(1),<br>    density = Density.create((density.dpiValue / factor).toInt().coerceAtLeast(1))<br>  )<br>}</pre><p>The factor defaults to 3, which puts a phone screenshot at 360 × 808. It’s a Gradle property, uk.co.fractalmotion.mugshot.downscale, and setting it to 1 renders at the device&#39;s real resolution. Values below 1 are rejected, because there&#39;s no extra detail to gain by rendering bigger than the device.</p><p>The resampling code went with it. With no bitmap to shrink, the resizing helpers in the image utilities had no callers left, and I deleted them.</p><h3>The results</h3><p>I compared release builds of Mugshot before and after the change, on the same machine, recording fresh golden images for each and running verify twice per side.</p><figure><img alt="Three bar charts, before and after: verify 88 to 64 seconds (−27%), record 99 to 75 seconds (−24%), golden images 155 to 86 MB (−45%)" src="https://cdn-images-1.medium.com/max/1024/1*V8IqsF1VBRqjfTlW-j-CPA.png" /><figcaption>Verify, record and disk usage before and after</figcaption></figure><figure><img alt="Table: verify took 88 and 87 seconds before and 63 and 65 after (−27%); record 99 to 75 seconds (−24%); verify summed across workers 1,012 to 742 seconds (−27%); per screenshot 141 to 103 ms (−27%); golden images 155 to 86 MB (−45%)" src="https://cdn-images-1.medium.com/max/1024/1*_h0OBYqSFSPSy9vUFcWZrw.png" /><figcaption>Before and after, measured on 7,176 screenshots</figcaption></figure><p>The disk saving is bigger than the time saving because two things stack up. There are fewer pixels to store, and the pixels compress better, since nothing is resampled afterwards and the image has no blended in-between colours along every edge.</p><p>The summed row is the one I’d pay the most attention to. On 15 cores Gradle got through about 11 cores’ worth of work at once, which hides a lot of per-screenshot cost behind parallelism. A CI runner with 4 cores gets much less of that help, so the saving it sees will be closer to the summed figure than to the wall clock on my machine.</p><h3>What happened to text</h3><p>Smaller renders should look worse, and text in particular should suffer when a glyph gets a third of the pixels. At normal size the before and after images looked the same to me. Zoomed in, the difference is more interesting than “better” or “worse”.</p><figure><img alt="Two zoomed crops of the same card with the text Shared playlist. On the left, rendered at 1080 by 2424 and shrunk: softer edges, even spacing. On the right, rendered at 360 by 808: crisper edges, slightly uneven letter spacing" src="https://cdn-images-1.medium.com/max/1024/1*9XbroFA7D9u8XEU9JNOLqg.png" /><figcaption>The same card, shrunk after rendering on the left and rendered small on the right, both enlarged</figcaption></figure><p>The old path was doing accidental supersampling. It drew the text at about two and a half times the final size and then averaged pixels together, which smooths every edge. Rendering at the final size lets the font rasteriser fit each glyph to the pixel grid, so the strokes on the right are crisper. The cost is visible too: at this size glyph positions snap to whole pixels, so the letter spacing gets uneven (“Del ivered”).</p><p>For a screenshot test that trade is fine. The golden image only has to change when the UI changes, and it does that just as reliably at a third of the resolution. If you need to read small text in a failure report, downscale = 1 gives you the full-size render back.</p><p>Smaller images also help whoever has to look at them. Reviewers load a pull request full of updated golden images faster. For an AI agent checking its own UI work, the saving is direct: most models charge for an image by its size in pixels, so a failure image at a third of the resolution in each direction costs roughly a ninth of the full-size one to inspect.</p><h3>Two caveats</h3><p>Density is divided by the factor, not snapped to one of Android’s density buckets. For a Compose or vector UI that makes no difference. A module that ships bitmaps in drawable-xxhdpi and friends can end up with a different bitmap than the real device would pick, because resource selection sees the scaled density. That&#39;s the main reason to set downscale = 1.</p><p>The other caveat is about upgrading. Every golden image changes size, so moving to this version meant re-recording all of them. It shipped in Mugshot 3.3.0, and the release notes say so in bold.</p><h3>Measurements that were wrong on the way</h3><p>Several numbers along the way were wrong, and each looked plausible at the time.</p><p>The first per-screenshot figure I calculated was 215 ms. I had divided one module’s wall-clock time by its screenshot count while 30 modules were running in parallel, so the figure mostly measured CPU contention. Measured in isolation, a screenshot took about 40 ms.</p><p>The timing hooks I used to find the hotspot cost about 25% on their own. At one point I compared an instrumented build against an uninstrumented baseline, and a 22 second improvement showed up as a 10 second regression.</p><p>Order mattered too. In one A/B run the faster build came out 8% slower, and swapping the order flipped the result: whichever build ran first on a quiet machine won by about 5 seconds. After that, every comparison ran each side in both positions.</p><p>I also tried two optimisations that looked good on paper and measured as nothing end to end. One was building the diff image only when a test fails, which removed around 36 GB of short-lived allocation from a full run. The other was reading pixels straight from the raster, which is 9.5× faster in isolation. Neither changed the wall-clock time. Short-lived allocations are cheap, and a 9.5× speedup on something that takes 2% of a screenshot’s CPU time doesn’t reach the clock.</p><h3>Try it</h3><p>The change shipped in Mugshot 3.3.0 and is on by default in every later version. If you use the annotations, you get it by upgrading and re-recording your goldens.</p><p>Mugshot is on GitHub at <a href="https://github.com/TRazDev/Mugshot">TRazDev/Mugshot</a> and on Maven Central as uk.co.fractalmotion.mugshot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31e4d33900f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Screenshot testing a Compose Multiplatform app without an emulator]]></title>
            <link>https://medium.com/@traz.developer/screenshot-testing-a-compose-multiplatform-app-without-an-emulator-e93ead9be817?source=rss-592d61341845------2</link>
            <guid isPermaLink="false">https://medium.com/p/e93ead9be817</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Artsiom Seliuzhytski]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 11:51:49 GMT</pubDate>
            <atom:updated>2026-09-18T11:51:49.943Z</atom:updated>
            <content:encoded><![CDATA[<h4>Adding Mugshot to a Kotlin Multiplatform project: about ten lines of Gradle and a few annotations per preview</h4><p>Compose Multiplatform lets you write a screen once in commonMain and ship it to Android, iOS and desktop. The flip side is that one change to shared UI lands on every platform at once, so it&#39;s worth knowing what that change did before it ships. Instrumented screenshot tests need an emulator, and they test the Android app, not the shared module where the UI lives.</p><p>Mugshot, the screenshot testing library I maintain, gained Kotlin Multiplatform support in version 3.4. This post walks through adding it to a small Compose Multiplatform app, what gets recorded, and what a failure looks like.</p><h3>The sample app</h3><p><a href="https://github.com/TRazDev/MugshotSampleKMP">Mugshot Farm</a> is a pretend control panel for an indoor farm. It has five screens (a dashboard, grow lights, fertiliser, water and solar), all written in commonMain. The Android, iOS and desktop apps are thin entry points that call the same App().</p><p>It uses the parts of Compose Multiplatform a real app would. Strings and a pixel font come from Compose resources through Res and stringResource, with English, Italian and Japanese translations. There&#39;s a light and a dark theme built from one set of tokens, the stat grids switch from two to four columns on wide windows, and one screen uses @PreviewParameter to preview both a healthy state and a faulty one.</p><figure><img alt="Five screens of the Mugshot Farm app, Dashboard, Grow Light, Fertiliser, Water and Solar, each shown in a light row and a dark row, in a retro pixel font" src="https://cdn-images-1.medium.com/max/1024/1*5wEPywmp--gLpC1cBNXjAg.png" /><figcaption>All five screens in light and dark, as recorded by Mugshot</figcaption></figure><p>Every image above is an unedited golden image from recordMugshot.</p><h3>Adding Mugshot</h3><p>The whole integration is <a href="https://github.com/TRazDev/MugshotSampleKMP/commit/d6d869e">one commit</a>. Leaving out the golden images and a few version bumps, it adds about ten lines of Gradle and two annotations to each of the five previews. A later commit widened the coverage, which I’ll come to.</p><p>Add KSP and Mugshot to the version catalog:</p><pre>[versions]<br>ksp = &quot;2.3.8&quot;<br>mugshot = &quot;3.4.2&quot;</pre><pre>[plugins]<br>ksp = { id = &quot;com.google.devtools.ksp&quot;, version.ref = &quot;ksp&quot; }<br>mugshot = { id = &quot;uk.co.fractalmotion.mugshot&quot;, version.ref = &quot;mugshot&quot; }</pre><p>Declare Mugshot in the root build file:</p><pre>plugins {<br>    // ...<br>    alias(libs.plugins.mugshot) apply false<br>}</pre><p>Then apply both plugins in the shared module and turn on host tests:</p><pre>plugins {<br>    alias(libs.plugins.kotlinMultiplatform)<br>    alias(libs.plugins.androidMultiplatformLibrary)<br>    alias(libs.plugins.composeMultiplatform)<br>    alias(libs.plugins.composeCompiler)<br>    alias(libs.plugins.ksp)<br>    alias(libs.plugins.mugshot)<br>}</pre><pre>kotlin {<br>    android {<br>        // ...<br>        androidResources {<br>            enable = true // already there, for Compose resources<br>        }<br>        withHostTest {<br>            isIncludeAndroidResources = true<br>        }<br>    }<br>}</pre><p>withHostTest is easy to miss. The Android KMP library plugin doesn&#39;t create a host test compilation unless you ask for one, and that compilation is where Mugshot generates and runs its test.</p><p>There are no dependencies to add. The plugin puts the annotations and the runtime on commonMain and the test machinery on androidHostTest.</p><h3>Annotating the previews</h3><p>The previews already existed in commonMain. In the first commit each one got @Mugshot and @MugshotLightDark. Today they carry two more:</p><pre>@Mugshot<br>@MugshotLightDark<br>@MugshotDevices<br>@MugshotLocales(&quot;en&quot;, &quot;it&quot;, &quot;ja&quot;)<br>@Preview<br>@Composable<br>internal fun SolarScreenPreview() {<br>    MugshotAppTheme { SolarScreen(state = MockSolarData.default) }<br>}</pre><p>The only other change was private to internal. The generated test has to call the preview function, and it can&#39;t call a private one. Mugshot has an optional lint check that turns a private annotated preview into an error, because otherwise it&#39;s skipped without a word.</p><h3>Recording</h3><pre>./gradlew :shared:recordMugshot</pre><p>Mugshot’s KSP processor finds every @Mugshot preview in the module, including the ones in commonMain, and generates a test that renders each of them. The images go to shared/src/androidHostTest/snapshots/images/, and you commit them.</p><p>The axes multiply. Four devices (phone, foldable, tablet and landscape), two themes and four locales (the default plus English, Italian and Japanese) make 32 images per preview. The grow light screen’s preview takes a @PreviewParameter with two states, so five previews produce 192 images. Adding the devices and locales was a change to annotations and nothing else.</p><p>The project also sets uk.co.fractalmotion.mugshot.downscale=2 in gradle.properties. Mugshot renders a third of each device&#39;s resolution by default, and 2 keeps a little more detail in the images.</p><p>The translated strings and the pixel font show up in the golden images because Mugshot sets up Compose resources before each render. I had to add that for version 3.4: without an Android Context, stringResource throws when a preview is rendered outside an app.</p><p>From here, this fails the build when a screen changes:</p><pre>./gradlew :shared:verifyMugshot</pre><p>Once the project is compiled, verifying all 160 screenshot tests takes about ten seconds on my machine, and when nothing has changed Gradle skips them entirely.</p><h3>When something breaks</h3><p>Here’s a regression that’s easy to ship. The condition that picks the column count on the solar screen gets flipped:</p><pre>- columns = if (windowSize == FarmWindowSize.Compact) 2 else 4,<br>+ columns = if (windowSize != FarmWindowSize.Compact) 2 else 4,</pre><p>It compiles, and on a desktop window it looks fine. On a phone, four stat tiles get squeezed into one row and the numbers wrap, and on the wider devices the grid goes the other way. verifyMugshot fails every one of the solar screen&#39;s tests, on each device, theme and locale:</p><pre>160 tests completed, 32 failed</pre><p>For every failure, Mugshot writes the golden image, a difference image and the new render into a single file for CI to upload, and the console error links straight to it. This one is the phone in light mode, captured while the sample still recorded light and dark only:</p><figure><img alt="Three panels of the Solar Grid screen on a phone: the expected golden image, a difference image with the broken stat grid in red, and the actual render with four tiles squeezed into one row" src="https://cdn-images-1.medium.com/max/1024/1*AL6IZ_q4i8Nqf1iXulCgpg.png" /><figcaption>The golden image, the difference in red, and the new render</figcaption></figure><p>Everything that moved is red, so it’s obvious the stat grid broke and the header didn’t. If the change was intentional, you record again and commit the new images with the code.</p><h3>Why the JVM helps here</h3><p>The tests run as plain JUnit tests in a Gradle task, rendering with layoutlib, the renderer behind Android Studio’s previews. There’s no emulator or simulator to download, boot or keep healthy on a CI machine, and no device timing to make a run flaky. A CI job needs the same JDK and Android SDK it already uses to build the app.</p><p>It also keeps the tests next to the code. The previews live in commonMain, the golden images live in the shared module, and a change to a shared screen and its new images land in the same pull request, where a reviewer can see what the change does to the UI without running the app.</p><p>That matters most for big changes. In a redesign or a refactor of the shared theme, verifyMugshot shows every screen that moved, in every device, theme and locale the sample records, and a refactor that was supposed to change nothing proves it by passing. Covering the same ground by hand would mean clicking through five screens, four devices and four languages on each platform.</p><p>It also means the UI tests that do run on a device can stay small. The screenshot tests already pin down how each screen looks, so instrumented tests can stick to behaviour, such as navigation and what happens on a tap.</p><h3>Letting an agent check its own work</h3><p>This setup is especially useful when an AI coding agent is changing the UI. To see what a change did without screenshot tests, an agent has to build the app, start an Android emulator or an iOS simulator, navigate to each screen, capture it and study the image. That’s slow, it’s easy for the agent to get lost along the way, and every screenshot it studies costs tokens.</p><p>With Mugshot the agent runs one Gradle task instead. The console output lists exactly which screens changed, so when nothing did, the agent knows without opening an image. When something did, it opens only the difference images for those screens, and each one shows it where the change is. After a deliberate redesign, recordMugshot gives it, and you, all 192 images to review at once.</p><p>The images are small as well. Mugshot renders devices at a fraction of their resolution, and most models charge for an image by its size in pixels, so checking a screen this way costs a lot less than studying a full-resolution emulator screenshot.</p><h3>What it doesn’t cover</h3><p>The images are Android renders. Your commonMain UI is drawn by Android&#39;s rendering stack, and where you use expect/actual, the Android actual is the one that runs. If an iOS-only implementation draws something differently, or a font renders differently on iOS, these tests won&#39;t see it.</p><p>A lot of what breaks in shared UI is layout, state and theming, which behave the same on every platform, and that’s the kind of change these tests catch. They don’t replace looking at the app on an iPhone.</p><p>A couple of details carried over from Android. Mugshot takes its configuration from its own annotations, so device, uiMode or fontScale set on @Preview changes the IDE preview but not the golden image. And use Mugshot 3.4.2 or newer. Earlier 3.4 releases need --no-configuration-cache in a module that uses Compose resources, and 3.4.0 was published without two of its multiplatform artifacts.</p><h3>Try it</h3><p>The sample is on GitHub at <a href="https://github.com/TRazDev/MugshotSampleKMP">TRazDev/MugshotSampleKMP</a>, and Mugshot itself is at <a href="https://github.com/TRazDev/Mugshot">TRazDev/Mugshot</a>. If your Compose Multiplatform project already has previews in commonMain, the setup above is all it takes to start recording them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e93ead9be817" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Screenshot tests for your Compose previews, with one annotation]]></title>
            <link>https://medium.com/@traz.developer/screenshot-tests-for-your-compose-previews-with-one-annotation-f0e106c5545a?source=rss-592d61341845------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0e106c5545a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[screenshot-testing]]></category>
            <dc:creator><![CDATA[Artsiom Seliuzhytski]]></dc:creator>
            <pubDate>Wed, 16 Sep 2026 17:26:17 GMT</pubDate>
            <atom:updated>2026-09-16T17:34:52.034Z</atom:updated>
            <content:encoded><![CDATA[<h4>Mugshot turns the previews you already have into screenshot tests that run on the JVM, with no test classes to write</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdIRCM3Y3dmS2ur68MYgPA.png" /><figcaption>One annotation and no test code</figcaption></figure><p>A Compose codebase of any size tends to collect @Preview functions. Someone wrote each one to see a screen in Android Studio, in light and dark, sometimes with a long name or an empty state, so together they describe what the UI should look like. Usually nothing checks them.</p><p>Screenshot tests would, but the usual setup asks you to write a test class that lists the screens and sets up devices in code, and to remember to add every new screen to it. That’s enough friction that coverage tends to stop at the screens someone thought of first.</p><p>I wanted a screenshot test to cost one annotation on a preview that already exists, and Mugshot is built around that.</p><h3>What it is</h3><p>Mugshot is an Android library and Gradle plugin. It renders Compose screens on the JVM using layoutlib, the same renderer Android Studio uses for previews, so there’s no emulator or device involved and tests run as ordinary unit tests.</p><p>It started as a fork of Square’s <a href="https://github.com/cashapp/paparazzi">Paparazzi</a> and has since become a library of its own. It generates tests from annotated previews instead of asking you to write them, supports Kotlin Multiplatform and the configuration cache, renders a smaller device for faster runs and smaller images, and runs screenshot tests in a Gradle task of their own.</p><h3>Why screenshot tests are worth having</h3><p>A screenshot test records what a screen looks like and fails when that changes.</p><p>Every state you have a preview for gets covered. With @PreviewParameter, one preview can render a screen loading, empty, populated and failing, and each state gets its own golden image. States that are awkward to reach in a running app, such as a network error on the third page of a list, are as easy to test as the happy path.</p><p>Large changes get safer. During a refactor or a redesign you can run the screenshot tests and see every screen in the app, on every device and theme you care about, in the time it takes to run a unit test suite. A refactor that was meant to change nothing should produce no failures. A redesign produces new golden images for exactly the screens it touched, and you can look through all of them before merging instead of finding a broken screen after release.</p><p>Code review gets a view of the UI. When a change affects how a screen looks, the pull request includes the updated golden images alongside the code, so a reviewer sees the effect on the UI without checking out the branch or running the app.</p><p>UI tests can get smaller. If screenshot tests already pin down how every screen looks, instrumented tests don’t need to assert on every text, icon and colour. They can concentrate on behaviour: navigation, input and what happens when a button is pressed.</p><h3>Setup</h3><p>Apply two plugins to a module that has Compose previews:</p><pre>plugins {<br>    id(&quot;com.google.devtools.ksp&quot;) // the KSP version that matches your Kotlin<br>    id(&quot;uk.co.fractalmotion.mugshot&quot;) version &quot;3.4.2&quot;<br>}</pre><p>Annotate a preview:</p><pre>@Mugshot<br>@Preview<br>@Composable<br>internal fun ProfileScreenPreview() {<br>    AppTheme { ProfileScreen(state = sampleProfile) }<br>}</pre><p>Record the golden images:</p><pre>./gradlew recordMugshotDebug</pre><p>Each annotated preview now has an image in src/test/snapshots/images/. Commit them, and from then on ./gradlew verifyMugshotDebug renders every preview again and fails if any of them changed.</p><p>The plugin runs a KSP processor that finds every @Mugshot preview in the module and generates one test that renders them all. You never see or edit that test. Add a preview and it&#39;s covered; delete one and its test goes with it.</p><h3>One preview, many images</h3><p>@Mugshot on its own records one image on the default device, a Pixel 10. Other annotations add axes, and the axes multiply:</p><pre>@Mugshot<br>@MugshotDevices(MugshotDevice.PHONE, MugshotDevice.TABLET)<br>@MugshotLightDark<br>@Preview<br>@Composable<br>internal fun ProfileScreenPreview() { ... }<br>// 2 devices × 2 themes = 4 images</pre><p>There are annotations for devices (phone, foldable, tablet, landscape and two watch shapes), light and dark, font scales, locales (right-to-left ones are mirrored), and a full-height mode for long scrolling screens. @MugshotMatrix is the big one: four devices, both themes and three font scales, 24 images from a single preview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JQH_eTAgwU42QbguxG4eSA.png" /><figcaption>The 24 images @MugshotMatrix records from one preview</figcaption></figure><p>Teams usually settle on a house style, so the annotations also work on annotation classes:</p><pre>@Mugshot<br>@MugshotDevices(MugshotDevice.PHONE, MugshotDevice.TABLET)<br>@MugshotLightDark<br>annotation class ScreenshotTest</pre><pre>@ScreenshotTest<br>@Preview<br>@Composable<br>internal fun ProfileScreenPreview() { ... }</pre><p>A preview that takes a @PreviewParameter gets one image per value, so one preview can cover a screen&#39;s loading, empty and error states.</p><h3>When a test fails</h3><p>A failed verification shows up in the HTML test report with three images side by side: the golden image, a difference image where every changed pixel is red, and the new render. The same images are written to build/mugshot/failures so a CI job can upload them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2m6PtykHHQae0PnEff_dDA.png" /><figcaption>A failed screenshot in the Mugshot report</figcaption></figure><p>To make CI fail on visual changes, hook verification into check:</p><pre>tasks.named(&quot;check&quot;) {<br>    dependsOn(&quot;verifyMugshot&quot;)<br>}</pre><h3>How fast it is</h3><p>I measure Mugshot on a generated project of 30 modules and 299 previews, every one of them annotated with @MugshotMatrix, which comes to 7,176 screenshots. On a 15-core Mac:</p><ul><li>Verifying all 7,176 screenshots, with nothing cached, takes 58 seconds.</li><li>Editing one feature module and verifying takes 6.7 seconds, because Gradle only re-runs screenshot tests for modules that changed.</li><li>When nothing has changed, verifyMugshotDebug finishes in about 300 ms.</li><li>With the configuration cache on, applying the plugin to all 30 modules adds 55 ms to configuration.</li></ul><p>Two changes account for most of that speed. Mugshot renders a smaller device, a third of the resolution by default, instead of rendering at full size and shrinking the image afterwards. That made verification 27% faster and the golden images 45% smaller. The other change is that the generated tests run in their own Gradle task and their own JVM, so verifyMugshot doesn&#39;t drag the rest of a module&#39;s unit tests along. That also stops layoutlib from colliding with Robolectric tests in the same module, which used to break them.</p><p>On the same 7,176 screenshots, Paparazzi took 89 seconds to verify, and Google’s Compose Preview Screenshot Testing ran out of memory with its default settings. The benchmark, with one branch per tool, is on GitHub at <a href="https://github.com/TRazDev/screenshot-testing-benchmark">TRazDev/screenshot-testing-benchmark</a>.</p><h3>A check that AI agents can run</h3><p>Coding agents now take on UI work too, from building a screen to applying a redesign across a whole app. The hard part for an agent is knowing whether the result looks right.</p><p>The usual way is to build the app, start an emulator, navigate to each screen, take a screenshot and look at it. It’s slow and easy to get wrong, and it’s expensive in tokens, because the agent has to reason its way through each step and then inspect a full-size image of every screen. For a change that touches the whole app, that’s dozens of screens.</p><p>Screenshot tests turn that into a single command. The agent runs ./gradlew verifyMugshot, and the output names exactly which screens changed. If nothing changed, it&#39;s done without looking at a single image. If something did, it only needs to look at the screens that failed, and the difference image shows it where. For an intended redesign, recordMugshot updates the golden images and every affected screen is there to review, on every device and theme, without an emulator ever starting.</p><p>Because Mugshot renders at a third of the resolution by default, the images an agent looks at are small too. Most models charge for an image by its size in pixels, so a phone screenshot at 360 × 808 costs far less to inspect than one at 1080 × 2424.</p><h3>Kotlin Multiplatform</h3><p>Mugshot works in Kotlin Multiplatform modules too. A preview in commonMain can be annotated the same way, strings and fonts from Compose Multiplatform resources render, and the configuration cache works. The images are Android renders of your shared UI. <a href="https://github.com/TRazDev/MugshotSampleKMP">MugshotSampleKMP</a> is a Compose Multiplatform app with it set up.</p><h3>What it doesn’t do</h3><p>Mugshot renders a single frame. It can capture a moment in an animation or its end state, but not the frames in between. There are no accessibility overlays either: a screenshot can only tell you the pixels match, and accessibility is better checked by tests that query the semantics tree.</p><p>The arguments on @Preview itself (device, uiMode, fontScale, locale) are ignored, and the Mugshot annotations are the source of truth. There&#39;s an optional lint check that warns when a preview sets them, because otherwise the IDE preview and the golden image can disagree without anything telling you.</p><p>Mugshot also leaves LocalInspectionMode unset, so a snapshot shows production output. A composable such as GoogleMap() that switches to a placeholder in previews won&#39;t do that under Mugshot unless you provide LocalInspectionMode yourself.</p><h3>Getting started</h3><p>Mugshot is on Maven Central as uk.co.fractalmotion.mugshot, and the source, documentation and a sample app are on GitHub at <a href="https://github.com/TRazDev/Mugshot">TRazDev/Mugshot</a>. If you already have previews, trying it takes two plugins, one annotation and one Gradle task.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0e106c5545a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>