<?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 Merve Pekyürek on Medium]]></title>
        <description><![CDATA[Stories by Merve Pekyürek on Medium]]></description>
        <link>https://medium.com/@merveylcu?source=rss-82da91b3da0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kuQseJRwB6EzCwdWJAU9SQ.jpeg</url>
            <title>Stories by Merve Pekyürek on Medium</title>
            <link>https://medium.com/@merveylcu?source=rss-82da91b3da0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:22:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@merveylcu/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[Screenshot Testing with Jetpack Compose and Azure DevOps CI/CD]]></title>
            <link>https://medium.com/peopleofpapara/screenshot-testing-with-jetpack-compose-and-azure-devops-ci-cd-3bac3f017016?source=rss-82da91b3da0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bac3f017016</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Merve Pekyürek]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 10:35:50 GMT</pubDate>
            <atom:updated>2025-05-05T07:35:50.236Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Ensuring UI consistency over time is critical for modern Android applications, especially when using declarative frameworks like Jetpack Compose. While unit tests validate logic, even a minor change in padding, color, or corner radius can break the visual layout. This is where </em><strong><em>Compose Screenshot Testing</em></strong><em> becomes essential. In this article, we’ll walk through how to set up Screenshot Testing and seamlessly integrate it into an Azure DevOps pipeline.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Hi-NxkiJJjQWYtBn3DMng.png" /></figure><h3>1. Introduction: Why Screenshot Testing?</h3><p>Although Jetpack Compose offers a flexible and expressive way to build UI, ensuring that the visual output remains consistent is not always straightforward. Small code modifications can lead to significant and unintended UI changes.</p><p><strong>Screenshot Testing</strong> helps solve this problem by:</p><ul><li>Automatically detecting visual regressions</li><li>Alerting developers about unintended UI changes</li><li>Ensuring stability with each code push via CI</li></ul><h3>2. Setup Instructions</h3><p>To enable screenshot testing, follow the steps below:</p><ul><li>Define the version of the plugin in your version catalogs:</li></ul><pre>[versions]<br>agp = &quot;8.5.0-beta01&quot;<br>kotlin = &quot;1.9.20&quot;<br>screenshot = &quot;0.0.1-alpha07&quot;<br><br>[plugins]<br>screenshot = { id = &quot;com.android.compose.screenshot&quot;, version.ref = &quot;screenshot&quot; }</pre><ul><li>Apply the Plugin in build.gradle.kts (Module Level):</li></ul><pre>plugins {<br>    ...<br>    alias(libs.plugins.screenshot)<br>}</pre><ul><li>In your `gradle.properties` file:</li></ul><pre>android.experimental.enableScreenshotTest=true</pre><ul><li>Add the dependency to your version catalogs:</li></ul><pre>[libraries]<br>androidx-compose-ui-tooling = { group = &quot;androidx.compose.ui&quot;, name = &quot;ui-tooling&quot; }</pre><ul><li>And reference it in your module build script:</li></ul><pre>dependencies {<br>    screenshotTestImplementation(libs.androidx.compose.ui.tooling)<br>}</pre><h3>3. Example Component: HelloView</h3><p>This is a basic composable that renders a styled label inside a bordered container:</p><pre>@Composable<br>fun HelloView(text: String) {<br>    PaparaText(<br>        modifier = Modifier<br>            .background(colorResource(PaparaThemeColor.pades_papara_white))<br>            .border(<br>                width = 1.dp,<br>                color = colorResource(PaparaThemeColor.pades_papara_black),<br>                shape = RoundedCornerShape(8.dp)<br>            )<br>            .padding(PaddingValues(horizontal = 8.dp, vertical = 6.dp)),<br>        text = text,<br>        fontSize = 14.sp,<br>        fontWeight = FontWeight.Bold,<br>        color = colorResource(PaparaThemeColor.pades_status_pending)<br>    )<br>}<br><br>@Preview(name = &quot;Light&quot;, uiMode = Configuration.UI_MODE_NIGHT_NO)<br>@Preview(name = &quot;Dark&quot;, uiMode = Configuration.UI_MODE_NIGHT_YES)<br>@Composable<br>fun PreviewHelloView() {<br>    HelloView(text = &quot;Hello Android Team&quot;)<br>}</pre><p>This component is rendered in both light and dark themes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*WsrQBeg9hzVqaWJWNPUhuw.png" /></figure><h3>4. Creating a Screenshot Test</h3><p>The following test must be placed in the screenShotTest source set inside your module’s src directory:</p><pre>@Preview(name = &quot;Light&quot;, uiMode = Configuration.UI_MODE_NIGHT_NO)<br>@Preview(name = &quot;Dark&quot;, uiMode = Configuration.UI_MODE_NIGHT_YES)<br>@Composable<br>fun HelloViewScreenShotTest() {<br>    PreviewHelloView()<br>}</pre><p>After creating this test, you need to generate the reference screenshots by running:</p><pre>./gradlew updateDebugScreenshotTest</pre><p>This command creates baseline images under your module’s build/outputs directory. These baseline images represent the expected UI appearance. In subsequent test runs, these images will be compared with newly rendered outputs to detect differences.</p><h3>5. Failure Case</h3><p>To simulate a test failure, we change the corner radius of HelloView from 8.dp to 12.dp and execute the validation command:</p><p>This results in the following visual difference and failure:</p><pre>./gradlew validateDebugScreenshotTest</pre><p>As expected, the rendered output now differs from the baseline, causing the test to fail. You can inspect the result in the generated diff image.</p><blockquote><em>Test results are available at: </em><em>build/reports/index.html. This includes reference, actual, and diff images for each test case.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*ZTf5d2FqGLy79BhofsTK9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ry_08PJSWiaMxe3i-3VPQ.png" /></figure><h3>6. Azure DevOps Pipeline Integration</h3><p>Below is a sample YAML configuration to integrate screenshot testing into your Azure DevOps CI/CD workflow:</p><pre>name: $(date:dd.MM.yyyy_HH.mm)<br><br>pool:<br>  name: Linux Mobile<br><br>trigger: none<br><br>pr: none<br><br>steps:<br>  - script: |<br>      CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) <br>      git fetch origin master<br>      git checkout master<br>      ./gradlew updateDebugScreenshotTest<br>      git checkout $CURRENT_BRANCH<br>      ./gradlew validateDebugScreenshotTest<br>    displayName: &#39;Generate and validate screenshots&#39;<br><br>  - task: PublishTestResults@2<br>    inputs:<br>      testResultsFiles: &#39;**/build/test-results/**/*.xml&#39;<br>      testRunTitle: &#39;Test Results&#39;<br>      failTaskOnFailedTests: true<br>    condition: always()</pre><h4>What does this YAML do?</h4><ol><li><strong>Update Baseline from Master</strong>: Checks out the latest baseline screenshots from the master branch by using updateDebugScreenshotTest.</li><li><strong>Validate Current Changes</strong>: Switches back to the original working branch and runs validateDebugScreenshotTest to compare new screenshots with the baseline.</li><li><strong>Publish Results</strong>: The PublishTestResults@2 task uploads the XML test results so they can be viewed in the Azure DevOps UI.</li><li><strong>Fail Build on Diff</strong>: If any screenshot differences are detected, the pipeline will fail (thanks to failTaskOnFailedTests: true).</li><li><strong>View HTML Report</strong>: All visual diffs and comparisons are stored in build/reports/index.html.</li></ol><h3>7. Pros and Cons of Screenshot Testing</h3><p>Before diving into best practices, it’s important to consider the advantages and limitations of screenshot testing as outlined in the official Android documentation.</p><h4>Advantages:</h4><ul><li><strong>Covers multiple UI aspects in one test</strong>: A single screenshot test validates layout, margins, colors, fonts, and positioning — all visually.</li><li><strong>Simpler than behavior tests</strong>: Screenshot tests are often easier to write, understand, and maintain compared to traditional UI tests with multiple assertions.</li><li><strong>Good for visual regressions across devices</strong>: They are particularly helpful for detecting regressions on varying screen sizes, densities, and themes.</li><li><strong>Clear diff visualization</strong>: Visual diffs make it easier to review changes without diving into layout code.</li><li><strong>No need to write manual assertions</strong>: Since the image is the truth source, manual assertions for padding or color are unnecessary.</li></ul><h4>Disadvantages:</h4><ul><li><strong>Slight platform differences</strong>: Linux, Mac, and Windows may render images slightly differently due to font rendering, anti-aliasing, or scaling.</li><li><strong>Cumbersome baseline management</strong>: Large projects can accumulate thousands of PNG files, which can be hard to manage.</li><li><strong>Slower than behavior tests</strong>: Rendering full UI elements and saving images takes longer than logic-based assertions.</li><li><strong>Broad impact from minor changes</strong>: A small UI change may affect hundreds or thousands of screenshots, making batch updates tedious.</li><li><strong>Debugging root causes is hard</strong>: While visual diffs highlight differences, they don’t always explain why the change occurred.</li><li><strong>Requires stable rendering</strong>: Flaky components or animated states can cause inconsistent screenshots across runs.</li></ul><blockquote><em>✔️ Use screenshot testing </em><strong><em>as a complement to functional tests</em></strong><em>, not a replacement.</em></blockquote><h3>8. Tips and Best Practices</h3><ul><li>Baseline screenshots are generated the first time tests are executed. Commit them to the master or main branch.</li><li>Always review diff images when a test fails. Use them to distinguish between regression bugs and intentional design updates.</li><li>Even minor pixel differences can cause test failures. Be precise with dimensions, padding, and shapes.</li><li>Use descriptive test names and organize screenshot tests alongside relevant UI components.</li></ul><h3>📚 References</h3><ul><li><a href="https://developer.android.com/studio/preview/compose-screenshot-testing">Compose Preview Screenshot Testing | Android Studio | Android Developers</a></li><li><a href="https://developer.android.com/training/testing/ui-tests/screenshot">Screenshot testing | Test your app on Android | Android Developers</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IXktgZ1IVw44p64c" /><figcaption>Photo by <a href="https://unsplash.com/@ianstauffer?utm_source=medium&amp;utm_medium=referral">Ian Stauffer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bac3f017016" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peopleofpapara/screenshot-testing-with-jetpack-compose-and-azure-devops-ci-cd-3bac3f017016">Screenshot Testing with Jetpack Compose and Azure DevOps CI/CD</a> was originally published in <a href="https://medium.com/peopleofpapara">Papara Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>