<?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 Konstantinos Lountzis on Medium]]></title>
        <description><![CDATA[Stories by Konstantinos Lountzis on Medium]]></description>
        <link>https://medium.com/@loukwn?source=rss-3f3b1b5f99d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uDR_NDhkMXtQTTxmWToAgw.jpeg</url>
            <title>Stories by Konstantinos Lountzis on Medium</title>
            <link>https://medium.com/@loukwn?source=rss-3f3b1b5f99d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:17:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@loukwn/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[Using Firebase to synchronize call events between two devices]]></title>
            <link>https://medium.com/@loukwn/using-firebase-to-synchronize-call-events-between-two-devices-7bf06fe7ebed?source=rss-3f3b1b5f99d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bf06fe7ebed</guid>
            <category><![CDATA[firebasecloudmessaging]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[broadcastreceiver]]></category>
            <dc:creator><![CDATA[Konstantinos Lountzis]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 17:37:04 GMT</pubDate>
            <atom:updated>2025-12-26T22:11:58.087Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rin7auBIK8CpgcWp" /><figcaption>Photo by <a href="https://unsplash.com/@isthatbrock?utm_source=medium&amp;utm_medium=referral">Brock Wegner</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Any expat out there will sympathize with the following situation:</p><blockquote>Soon after moving to your new country, you acquire a new phone number that will become your main one (to communicate with government / healthcare services, friends / coworkers / acquaintances, recruiters, scam callers of your new country etc.). However you still need your old phone number for those older relatives that do not want to change their habits, the home country’s government / bank / scam callers etc.</blockquote><p>The problem at hand now is how to manage both of these phone numbers.</p><p>One solution is to get a smartphone that supports multiple sims, in which case you can safely ignore the rest of this article (you get a few minutes back in your day and boy as working professionals don’t we love the sound of this sentence!).</p><p>If however for any reason this is not possible / desirable for you then probably the only solution for you is to have a separate phone lying around for that old phone number.</p><p>This from my experience comes with a couple of pain points:</p><ul><li>I only reliably see the calls that arrive on that phone if I am at home or in the vicinity of the device. Any other calls I acknowledge with a delay (which is a problem if they are urgent).</li><li>That other device (since it is generally unused) runs out of battery soon (even if it lasts way longer than my main one).</li><li>I could solve both of these issues by simply carrying both of these phones with me all the time (but let’s be real who wants to do that?).</li></ul><p>The general solution for me was to somehow make my main phone aware that the old one just had a call so I can action it from there.</p><h3>Detecting phone events</h3><p>The common denominator of all my explored solutions is that I needed an app that can:</p><ul><li>Detect when a phone call is received</li><li>Detect when the battery is low (and phone is not charging)</li></ul><p>…and do <em>something </em>to notify my main phone so I can action these things accordingly.</p><p>To address the first point created an app in which I setup a BroadcastReceiver that specifically listens to android.intent.action.PHONE_STATE events, gets the incoming phone number from the TelephonyManager and optionally does a lookup to get the contact name as so:</p><pre>class IncomingCallReceiver : BroadcastReceiver() {<br><br>  override fun onReceive(context: Context, intent: Intent) {<br>    // Only proceed if the event was ACTION_PHONE_STATE_CHANGED<br>    if (intent.action != TelephonyManager.ACTION_PHONE_STATE_CHANGED) return<br><br>    val telephonyManager =<br>        context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager<br>    val state = telephonyManager.callState<br>    <br>    // Check if the phone is ringing atm<br>    if (state == TelephonyManager.CALL_STATE_RINGING) {<br><br>      // Get the incoming phone number. This will be null unless READ_CALL_LOG <br>      // permission is granted.<br>      val phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) <br>        ?: return<br><br>      // (Optionally) Get the name of the contact that is calling you.<br>      val contactName: String? =<br>        getContactNameFromNumber(context = context, phoneNumber = phoneNumber)<br><br>      // Now notify somehow the other phone with the phoneNumber and contactName<br>      // that we have...<br>    }<br>  }<br><br>  /* <br>   * This will try to get the name of the contact using the given phoneNumber.<br>   * The result will be null if the phone is not saved as contact or if the <br>   * permission READ_CONTACTS is not granted.<br>   */<br>  private fun getContactNameFromNumber(context: Context, phoneNumber: String): String? {<br>    val uri = Uri.withAppendedPath(<br>      /* baseUri = */ ContactsContract.PhoneLookup.CONTENT_FILTER_URI,<br>      /* pathSegment = */ Uri.encode(phoneNumber)<br>    )<br>    val projection = arrayOf(ContactsContract.PhoneLookup.DISPLAY_NAME)<br>    var contactName: String? = null<br><br>    context.contentResolver.query(uri, projection, null, null, null)?.use { cursor -&gt;<br>      if (cursor.moveToFirst()) {<br>        contactName = cursor.getString(0)<br>      }<br>    }<br><br>    return contactName<br>  }<br>}</pre><p>Furthermore this is needed inside AndroidManifest.xml :</p><pre>&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_CALL_LOG&quot; /&gt;<br>&lt;!-- Optional. Feel free to ignore it --&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt; <br><br>&lt;!-- other manifest stuff... --&gt;<br><br>&lt;receiver<br>  android:name=&quot;.services.IncomingCallReceiver&quot;<br>  android:enabled=&quot;true&quot;<br>  android:exported=&quot;false&quot;&gt;<br>  &lt;intent-filter&gt;<br>    &lt;action android:name=&quot;android.intent.action.PHONE_STATE&quot; /&gt;<br>  &lt;/intent-filter&gt;<br>&lt;/receiver&gt;</pre><p>Now for the low battery event I initially wanted to do something similar to the above, but as per the <a href="https://developer.android.com/training/monitoring-device-state/battery-monitoring#MonitorLevel">docs</a>, this work will be better suited for WorkManager . So what I ended up doing is declaring the worker as so:</p><pre>class BatteryCheckWorker(<br>    private val context: Context,<br>    workerParameters: WorkerParameters,<br>) : CoroutineWorker(context, workerParameters) {<br><br>    override suspend fun doWork(): Result {<br>        val batteryState = getBatteryState(context)<br>        if (!batteryState.isCharging &amp;&amp; batteryState.level &lt;= BATTERY_LEVEL_LIMIT) {<br>            // We should notify the other phone here... <br>        }<br><br>        return Result.success()<br>    }<br><br>    private fun getBatteryState(context: Context): BatteryState {<br>        val batteryStatus: Intent? = IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter -&gt;<br>            context.registerReceiver(null, ifilter)<br>        }<br><br>        val status: Int = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) ?: -1<br>        val isCharging: Boolean = status == BatteryManager.BATTERY_STATUS_CHARGING<br>                || status == BatteryManager.BATTERY_STATUS_FULL<br><br>        val level: Float = batteryStatus?.let { intent -&gt;<br>            val level: Int = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)<br>            val scale: Int = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)<br>            level * 100 / scale.toFloat()<br>        } ?: 0f<br><br>        return BatteryState(<br>            level = level.toInt(),<br>            isCharging = isCharging,<br>        )<br>    }<br><br>    private data class BatteryState(<br>        val level: Int,<br>        val isCharging: Boolean,<br>    )<br><br>    companion object {<br>        private const val BATTERY_LEVEL_LIMIT = 25<br>    }<br>}</pre><p>which I initialize as:</p><pre>private fun initBatteryWorker() {<br>  val workRequest = PeriodicWorkRequest.Builder(<br>    BatteryCheckWorker::class.java,<br>    PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, // 15 Mins<br>    TimeUnit.MILLISECONDS,<br>  ).build()<br><br>  WorkManager.getInstance(context).enqueueUniquePeriodicWork(<br>    &quot;batteryChecker&quot;,<br>    ExistingPeriodicWorkPolicy.KEEP,<br>    workRequest,<br>  )<br>}</pre><p>The gist of it is we create a PeriodicWorkRequest that every 15 mins ( MIN_PERIODIC_INTERVAL_MILLIS ) will check the battery status and will only notify if the battery is below a critical threshold and is not charging.</p><p>With all that out of the way, we have a way to tell if the phone has an incoming call and also can tell if the battery is low at the moment. Let’s see how we communicate it!</p><h3>Exploring ideas about the communication</h3><p>I had a couple of ideas about this problem.</p><ol><li>I first thought about sending an SMS between the two devices. This could work in theory but I ideally did not want any weird carrier charges (remember the old one is on roaming mode).</li><li>Then I thought about sending an email to myself using my connected Gmail account. This turned out to be messy since I could either send an email Intent (which was a no go as I needed a completely hands free solution), or do the hacky thing of hardcoding my credentials in there and setup my app in a way that can communicate to Gmail (which I am pretty sure no matter how well I implement, Google will deem it insecure and will block the communication).</li></ol><p>Finally I thought that a sender / receiver sort of model would be appropriate for me. I know <a href="https://firebase.google.com/docs/cloud-messaging">Firebase Cloud Messaging</a> (FCM) is a good candidate for communicating with a specific device so what the idea ended up being is:</p><blockquote>The sender (phone being called) sends the events to Firebase via <a href="https://firebase.google.com/docs/functions">Firebase Cloud Functions</a>, then Firebase sends the events to the receiver (main phone) via FCM.</blockquote><h3>Setting up Firebase and writing related code</h3><p>Here is how I set everything up:</p><p>First of all we need to create a Firebase project, set up Firebase CLI locally and get it ready to deploy Firebase Cloud Functions. Not going to get into the nitty and gritty of it as we will go out of scope for this article but <a href="https://support.google.com/appsheet/answer/10104995?hl=en">this</a> and <a href="https://firebase.google.com/docs/functions/get-started?gen=2nd">this</a> articles will do a much better job at explaining the process anyway.</p><p>With the setup out of the way let’s see how the cloud functions will actually look like.</p><p>First I defined the functions as so:</p><pre>export const phoneCall = functions.https.onCall(async (data, context) =&gt; {<br>  const {phoneNumber, contactName, time} = data;<br><br>  const body =<br>    `You had a new call from ${contactName || phoneNumber} at ${time}.`;<br>  const message: admin.messaging.TopicMessage = {<br>    notification: {<br>      title: &quot;New phone call!&quot;,<br>      body: body,<br>    },<br>    android: {<br>      priority: &quot;high&quot;,<br>    },<br>    topic: &quot;phoneEvents&quot;,<br>  };<br><br>  try {<br>    await admin.messaging().send(message);<br>    return {success: true};<br>  } catch (error) {<br>    console.error(&quot;Error sending FCM message:&quot;, error);<br>    throw new functions.https.HttpsError(<br>      &quot;internal&quot;,<br>      &quot;Failed to send notification&quot;<br>    );<br>  }<br>});<br><br>// The battery one is almost identical. Just a different message and no other<br>// arguments apart from the time.<br>export const lowBattery = //...</pre><p>Basically it receives as part of the request an object that contains the phoneNumber , contactName (optionally), and the time this event happened. Then it constructs a message with these and sends a high priority TopicMessage using FCM. I chose a TopicMessage mainly because I found it easier to use (do not have to bother about keeping track of devices as a device can just subscribe to topics). It also has the added benefit that I could have multiple senders / receives should I want to.</p><p>Then on the sender side we can call this function like this:</p><pre>fun handleLowBatteryBatteryEvent() {<br>  callCloudFunction(&quot;lowBattery&quot;)<br>}<br><br>fun handlePhoneCallEvent(event: Event.PhoneCall) {<br>  callCloudFunction(<br>    name = &quot;phoneCall&quot;,<br>    payload = hashMapOf(<br>      &quot;phoneNumber&quot; to event.number,<br>      &quot;contactName&quot; to event.contactName,<br>    ),<br>  )<br>}<br><br>private fun callCloudFunction(name: String, payload: HashMap&lt;String, Any?&gt; = hashMapOf()) {<br>  val simpleDateFormat = SimpleDateFormat(&quot;HH:mm&quot;, Locale.getDefault())<br>  val time = simpleDateFormat.format(Date())<br>  val newHashMap = payload.plus(&quot;time&quot; to time)<br><br>  Logger.d(&quot;Calling $name with payload: $newHashMap&quot;)<br><br>  Firebase.functions<br>    .getHttpsCallable(name)<br>    .call(newHashMap)<br>    .addOnCompleteListener { task: Task&lt;HttpsCallableResult?&gt; -&gt;<br>      if (task.isSuccessful) {<br>        Logger.d(&quot;$name called successfully&quot;)<br>      } else {<br>        Logger.e(&quot;Failed to call $name&quot;, task.exception)<br>      }<br>    }<br>}</pre><p>Finally I chose to reuse the app for both senders and receivers. The sender does all the above, whereas the receiver just subscribes to the phoneEvent topic:</p><pre>private fun subscribeToMessages() {<br>  Firebase.messaging.subscribeToTopic(&quot;phoneEvents&quot;)<br>}</pre><p>After deploying all the above, running the two apps in their respective mode and making a phone call towards the sender, you should something like this after a while on the receiver. 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*wSHVCl6Nj1n-SzBmr9w4YA.png" /><figcaption>Example of received notification (I know you checked the number and then realized it is fake so sorry)</figcaption></figure><h3>A general note about Firebase Cloud Functions</h3><p>Firebase Cloud Functions (as most things in life) are not completely free but they are <strong>effectively free </strong>for our use-case.</p><p>At the time of writing this article (June 2024), in order to use them you have to be in the <strong>Pay as you go (Blaze) </strong>plan. <a href="https://firebase.google.com/pricing">According to the plan</a> however you get 2M (as in million) invocations for free every month which (hopefully for your sanity) is much more than enough.</p><p>Still because this may make some people nervous (as lots of people have been overcharged by mistake in the past etc.) and because someone reading this might want to use them for a completely different project, here are some tips to keep on top of the charges and hopefully sleep easier at night:</p><ul><li>If you are distributing an app in the wild and / or are afraid that your device has been tampered with, then you can use <a href="https://firebase.google.com/docs/app-check">App Check</a></li><li>You can choose to setup a budget so that you are aware if it starts charging on time, as they mention on their <a href="https://firebase.google.com/docs/projects/billing/avoid-surprise-bills">Avoid Surprise bills</a> article. It’s also worth noting that this will not shut them down if the budget is crossed (you will just get notified).</li><li>If you actually want to hard cap your usage AFAIK there is no official way but you can try some community workarounds like <a href="https://blog.minimacode.com/cap-firebase-spending/">this one</a>. As a disclaimer though I have to say I have not attempted this one and therefore will not be held responsible for any damage it may cause.</li></ul><h3>Wrapping up</h3><p>In this article I presented a way to communicate between two Android devices using Firebase Cloud Functions and Firebase Cloud Messaging. This can easily extend to multiple platforms, to support multiple events etc.</p><p>I realize my use-case is quite niche but I think people that do not have the same problem can definitely benefit from this write-up since it covers many smaller interesting topics.</p><p>The code for the app I created can be found here:</p><p><a href="https://codeberg.org/loukwn/pairifier">pairifier</a></p><p>Thanks a lot for your time if you made it all the way to the end and keep on automating your life!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bf06fe7ebed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sanely Test Your Android UI Libraries With Paparazzi]]></title>
            <link>https://medium.com/better-programming/sanely-test-your-android-ui-libraries-with-paparazzi-b6d46c55f6b0?source=rss-3f3b1b5f99d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6d46c55f6b0</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Konstantinos Lountzis]]></dc:creator>
            <pubDate>Sat, 12 Feb 2022 17:57:38 GMT</pubDate>
            <atom:updated>2022-03-06T18:28:45.448Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create a proper verification process for Android UI libraries using snapshot testing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2qPljspXaj_-7h71" /><figcaption>Photo by <a href="https://unsplash.com/@maurogigliphoto?utm_source=medium&amp;utm_medium=referral">Mauro Gigli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Testing should be the most important thing a dev thinks about while writing (or attempting to write) shippable code.</p><p>No matter how important it is though, testing sometimes can be inherently difficult.</p><p>This is especially true on Android UI libraries where things like Unit testing or UI testing (using Espressο, UiAutomator) start to make less sense.</p><h3>My use case</h3><p>The problem I had to sort was trying to test <a href="https://github.com/loukwn/StageStepBar">my library StageStepBar</a>.</p><p>It is essentially a progress bar that can contain Stages (milestones) and individual steps between them. It is also quite configurable, effectively allowing you to change the look and behavior of all its components. It is really a big Custom View with most of its code inside its onDraw.</p><p>All seemed fine and dandy until I realized that the way I could test it after changing stuff was very cumbersome. I did thankfully include a sample application but I essentially had to modify, build and run the application to check that my changes were affecting the library in the correct way. But even that process was not bulletproof enough as:</p><ul><li>Sometimes I would forget to retest some cases.</li><li>Other times I would not test some cases that would seem irrelevant but would be “mysteriously&quot; affected.</li><li>This whole thing still involved one device. What happens with different ones? RTL locales? The list could go on…</li></ul><h3>Enter snapshot testing</h3><p>While attending Droidcon 2021 @ London I got introduced to another way of testing things in the Android world - snapshot testing. <a href="https://www.droidcon.com/2021/11/17/an-introduction-to-effective-snapshot-testing-on-android-2/">Here is a nice talk about this topic</a>.</p><p>The gist of it is:</p><ul><li>You take a bunch of screenshots and/or videos of your UI.</li><li>If you are happy with them you store them in someplace in your repo as golden values/sources of truth.</li><li>If any changes are made, a verification algorithm (usual pixel by pixel comparison) runs through your code and compares the golden values with the new screenshots.</li><li>If these changes are expected/desired, the screenshots will be replaced. Otherwise, the code is breaking some things that it shouldn’t.</li></ul><p>This seemed like just the right approach for my use case. However, a specific library that was showcased at that event called Paparazzi actually convinced me that it is.</p><h3>What is Paparazzi</h3><p>This is yet another snapshot testing library but the difference with other currently available solutions (see <a href="https://github.com/pedrovgs/Shot">Shot</a> for example) is that it runs completely on the JVM without the need of a device or emulator.</p><p><a href="https://www.droidcon.com/2021/11/17/keeping-your-pixels-perfect-paparazzi-1-0-2/">This talk from the same Droidcon goes</a> into more detail about how it works.</p><p><a href="https://github.com/cashapp/paparazzi">https://github.com/cashapp/paparazzi</a></p><p>This was really convenient for my use case as it meant that I could use Github Actions to create a way for both me and any future contributors to get some fast feedback on whether their changes broke something.</p><p>It is worth noting that at the time of writing (12th of Feb 2022) the library is not stable yet. Complete documentation is not fully there and stuff seems like it is still being worked on. So it might be that what you see here may not work the same in a few months. Also at the time of writing again, there was no Compose support.</p><p>So with all that out of the way, here is the full process I followed:</p><h3><strong>Writing tests (Recording process)</strong></h3><p>First of all, I created a simple library module. This module:</p><ul><li>Depends on the StageStepBar module (which is the one under test).</li><li>Has the Paparazzi plugin applied to it. This gives it the record and verifies Gradle tasks which we will use later.</li><li>Contains the tests and the golden values (screenshots) under src/test and src/test/snapshots accordingly.</li></ul><p>An example of the tests we can write is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fa0809210a2910bb6a5d82db150dc86/href">https://medium.com/media/0fa0809210a2910bb6a5d82db150dc86/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87a12cd4781ae846766784449b41fedf/href">https://medium.com/media/87a12cd4781ae846766784449b41fedf/href</a></iframe><p>Essentially we have a layout file with the view that we want to test. Paparazzi inflates it with its special context using paparazzi.inflate().</p><p>We can then get access to that view and get it to a state that we want it to be in for each particular test case.</p><p>Then calling paparazzi.snapshot() seals the deal as it will render the first frame of everything that we have set up into a screenshot file. If we want more than just a frame (say we are testing animations), then we can use the handy paparazzi.gif() method. The result after running gradle module-name:testDebug on that module is these two screenshots:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJ18Dax6SvOwMJvjUgFLVg.png" /></figure><p>All these snapshot files sit inside the build/ folder now. If we are happy with how everything looks we can just run:</p><pre>gradle module-name:recordPaparazziDebug</pre><p>This will put these files under src/test/snapshots as well thus making them available to be checked in with git. Now our source of truth has been created!</p><p><strong>Note:</strong> It is worth noting that using LFS for these files is highly recommended by the Paparazzi authors. As screenshots will change in the future so will the git history become full of these binary blobs. LFS makes it possible to instead save pointers that will point to remote files on another server, make the whole process easier and faster for you. Both Paparazzi and Github docs contain setup guide.</p><h3>Testing against code changes (Verifying process)</h3><p>After all the above has been pushed to the repo it’s time to think about how will these things be enforced from now on. So for that I created a GitHub actions workflow that will for every push on an open PR:</p><ul><li>Run the gradle module-name:verifyPaparazziDebug task to compare the screenshots that the PR code would output against the golden values.</li><li>If any of the tests fail, then an image with the expected/actual screenshots together with their delta will be uploaded as an artifact in that run (per test failed). It will also put a comment on the PR that will point the dev to the artifacts section so that they can study the errors. The delta is a really nice extra that we get from the library. Here is how that looks:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8nu4AL9ZZpea-0retildg.png" /><figcaption>Image showing the Actual/Expected/Delta of a single test (created by Paparazzi)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*_Tb0d3h_m1L-pg2YrfygOA.png" /><figcaption>PR message by CI when Snapshot testing has <strong>failed</strong></figcaption></figure><ul><li>If all tests pass instead then a happy message is posted on the PR instead.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*iBM7jwE_EDON_Ubjv2AXTQ.png" /><figcaption>PR message by CI when Snapshot testing has <strong>succeeded</strong></figcaption></figure><p>The full CI workflow looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556583bcd86743b03f01a600fb4abec7/href">https://medium.com/media/556583bcd86743b03f01a600fb4abec7/href</a></iframe><p>But what happens if changes are desired? In that case, the reviewer (well me in this case) can approve the PR and ask the author to run the record task on their code and push the resulting snapshots.</p><p>Then finally when that PR is merged into the main branch the golden values will be updated.</p><h3>Final Thoughts</h3><p>I really believe that snapshot testing with Paparazzi can be a particularly effective way to create a proper verification process for Android UI libraries that had a hard time being tested before. The fact that it runs straight on the JVM means no emulator/device setup, fast execution, and easier integration with CI.</p><p>Massive props to the folks that are working on this great library that I am merely using!</p><p>I am quite keen to see what you people think about all this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d46c55f6b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/sanely-test-your-android-ui-libraries-with-paparazzi-b6d46c55f6b0">Sanely Test Your Android UI Libraries With Paparazzi</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>