<?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 Hein Sek on Medium]]></title>
        <description><![CDATA[Stories by Hein Sek on Medium]]></description>
        <link>https://medium.com/@heynxsehhz?source=rss-55be615b3f93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OOG9r_ITB3j0EZOj.jpg</url>
            <title>Stories by Hein Sek on Medium</title>
            <link>https://medium.com/@heynxsehhz?source=rss-55be615b3f93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:44:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@heynxsehhz/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[A Simple Way to Do Error Handling]]></title>
            <link>https://medium.com/@heynxsehhz/a-simple-way-to-do-error-handling-5b9683d4ec7d?source=rss-55be615b3f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b9683d4ec7d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[maintainability]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[Hein Sek]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 13:53:43 GMT</pubDate>
            <atom:updated>2026-06-10T06:34:12.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnIcQWFK-wEsK8zszeOuNw.png" /></figure><p>One of the reasons why we do error handling in apps, is to display helpful error messages to users in error cases. The app should tell them what happened and what they should do after the error. Displaying an informative error message is a good user experience. Just displaying “Something went wrong” doesn’t make sense.</p><p>Another reason is to nudge the user to do some actions in special error cases such as routing the user to login page if the session is expired.</p><p>And of course, the way we do error handling need to be scalable as our apps will have many features and API/Service calls.</p><p>In this article, I will describe a simple way of error handling. Let me use mobile app as the platform of the system. I think the concepts are applicable for other systems where MVVM or clean architecture is used, as well.</p><p>This article will use Flutter and MVVM. So some prerequisite knowledge about them, is required. Clean architecture is fine too.</p><p>So let’s get started.</p><p>Most apps usually have the following requirements regarding the error handling.</p><ul><li>as a mobile app, it should display error messages contained in backend API responses. This is for special cases where backend returns an error message. For example, you provided an invalid user ID in API payload.</li><li>the app should display error messages for some well known http status codes like “System error at our side” for status code 500. “Unauthorized. Please login again” for status code 401.</li><li>the app must display error messages in common cases like device has no internet connection.</li><li>the app should be able to do some special actions based on backend api response. For example, route the user to login page if session expired and backend returns 401. This kind of special actions could be anything based on the feature of the app or API it consumes.</li><li>most importantly, since the app will have various and many features and API/services it consumes, the way of handling error has to be scalable, which means it is flexible based on requirements, easy to modify the behavior — like change in one place, affect all places in app, and no need to change in every places it occurs.</li></ul><p>Error handling requirements can be vary based on apps. Your app could have different requirements. But most are basically the same concepts. The method I will mention later can work for most requirements.</p><p>So let’s talk about a simple way of error handling that cover above requirements.</p><p>As you know, in MVVM architecture, we have:</p><p>View: for presenting data, accepting user actions.</p><p>ViewModel: holds the app’s state and contains the logic for the UI. It requests data from the Model, processes it, and serves it up on a silver platter for the View to display.</p><p>Model: we usually divide this to Repository and Service/API classes in Flutter. Basically, it fetches the raw data (e.g., pulling a JSON response from a server or querying a local database) and formats it. And gives it to ViewModel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CnGFZmRTaewAXvGho8hH4A.png" /><figcaption>(MVVM architecture. Image credit to <a href="https://docs.flutter.dev/app-architecture/guide">https://docs.flutter.dev/app-architecture/guide</a> )</figcaption></figure><p>One simple way to do error handling is as the following:</p><p><strong>Service/API class: return data or throw exception</strong></p><p>It will call an API and if okay, it will return the data.</p><p>In error cases such as no internet connection, or exceptions like edge cases our backend handle, or common error cases like 401 unauthorized, it will throw an exception.</p><p><strong>Repo: return data or throw exception</strong></p><p>Repo could just calls Service/API and might not need to do any try catch here. So the exception from Service/API class will be propagated to ViewModel. But in case the exceptions propagated from Service/API classes are low level and not ready for ViewModel, Repo can process and refine them before giving to ViewModel.</p><p><strong>ViewModel: emit state based on data/exception</strong></p><p>It handles the exceptions from Repo. Exceptions could be general ones with an error message or dedicated for a purpose such as “UnauthorizedException”. It can check the exception and tell the view to just display the error message, or do some actions like routing the user to login page in case it is “UnauthorizedException”</p><p><strong>View: present data or error message</strong></p><p>If ViewModel gives data, view displays it. In error cases, it can just display the error message or it can do some actions as it likes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnIcQWFK-wEsK8zszeOuNw.png" /><figcaption>Error Handling flow</figcaption></figure><p>In short, this method just use try catch and propagate the exception along the way to ViewModel.</p><p>I demonstrated this error handling method in <a href="https://github.com/HeynSekk/flutter_coding_assignment">this</a> simple Flutter project. That app calls a dummy json API. In Add Post feature, it calls a simple api endpoint “posts/add” providing “userId”, “title” and “body”.</p><p>In Service/API class, it throws exception by using a helpful “ExceptionHandler” class for the purpose of scalability and flexibility.</p><p>That project handles error cases like device having no internet connection, 401 unauthorized, and other http status codes. Essentially, it cover the requirements mentioned above. And I think this method is fundamental and can be extended based on our requirements.</p><p>Happy building!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b9683d4ec7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making sure our apps are compatible with new versions of Android & iOS]]></title>
            <link>https://medium.com/@heynxsehhz/making-sure-our-apps-are-compatible-with-new-versions-of-android-ios-4e5481e94547?source=rss-55be615b3f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5481e94547</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[os-version]]></category>
            <category><![CDATA[android-sdk]]></category>
            <category><![CDATA[ios-sdk]]></category>
            <category><![CDATA[behavior-change]]></category>
            <dc:creator><![CDATA[Hein Sek]]></dc:creator>
            <pubDate>Sun, 23 Mar 2025 11:11:34 GMT</pubDate>
            <atom:updated>2026-05-16T12:32:18.310Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1JDPYqlxO0gkBuTEM7i5g.png" /></figure><p>Every year, Google and Apple release a new version of Android and iOS, bringing changes to the operating systems that enhance performance, privacy, security, robustness, and overall quality. Sometimes (but rarely), these changes can impact our Android and iOS apps — whether written in native languages or cross-platform frameworks like Flutter — causing issues when running on the latest OS versions.</p><p>This article explains how to proactively handle these OS changes to ensure our apps continue working seamlessly. First, it covers key concepts of Android and iOS SDKs, how the OS, SDK, and related components evolve together, and then outlines a strategy for migrating our apps to new OS versions without causing issues for users. Hopefully, it will be useful for Flutter developers who lack native Android and iOS experience. This is going to be a long article and grabbing a coffee or activating our reading mood might be needed :D. So let’s get started!</p><h4>💐 What do these changes look like?</h4><p>Changes are related to various aspects of the OS, including framework APIs, privacy, device hardware and security.</p><h4>💐 Framework API changes?</h4><p>The Android framework provides a set of APIs, known as framework APIs, that applications use to perform various tasks within the OS, such as accessing hardware (camera, Bluetooth, audio), managing background and foreground services, and working with file storage.</p><p>Each Android version has a defined set of APIs, referred to as an API level. For example, the API set for Android 16 is called API level 36, while that for Android 15 is API level 35.</p><p>These APIs may be deprecated, removed, or replaced in new OS releases, while new APIs may also be introduced. If your app runs on a new OS version and calls an API that has been removed, it may crash or behave unexpectedly.</p><p>You can view API changes and compare them across Android SDK versions — including which APIs have been added or removed — <a href="https://developer.android.com/sdk/api_diff/36/changes/changes-summary">here</a>.</p><h4>💐 AndroidX Libraries</h4><p>Android separates framework APIs from a set of libraries known as AndroidX. These libraries generally serve as wrappers around framework APIs, providing backward compatibility for developers. This means app developers don’t have to handle compatibility for different OS versions manually — AndroidX libraries take care of that.</p><p>AndroidX consists of various libraries, each serving a specific purpose. For example, there is a library for biometric authentication, another for network access, and many more.</p><p>However, AndroidX does not wrap all framework APIs — only some of them. In cases where a framework API is not covered by AndroidX, you may need to call it directly and implement API availability checks for different OS versions.</p><p>Unlike the Android SDK and platform, AndroidX libraries are released separately. This allows Google to update, improve, and release new versions of these libraries frequently, ensuring they evolve alongside the Android SDK and framework APIs. As you adapt your app for API changes, you’ll often need to upgrade these libraries if you’re using them.</p><h4>💐 iOS’s approach for APIs and libraries</h4><p>iOS takes a slightly different approach when it comes to APIs. The iOS SDK provides APIs that apps can use to access native features of the OS. Similarly, it includes “native frameworks,” which developers can use like libraries without needing to call platform APIs directly. These frameworks are tied to the iOS SDK and do not have independent versions like AndroidX libraries. Instead, they evolve together with the iOS SDK.</p><p>When Apple rolls out bug fixes for these frameworks, they release them alongside the iOS SDK, Xcode (since the iOS SDK is coupled with Xcode), and the iOS Simulator. Sometimes you may need to use multiple versions of iOS SDK when you try beta versions of the SDK and related components. In those cases, you can install multiple versions of Xcode on your Mac.</p><p>So when a new iOS version is released and you want to use its new APIs, enhancements in native frameworks, or adapt your app to API changes, you need to download a new version of Xcode (a beta version if it’s before the final release). This new Xcode version includes the corresponding iOS SDK. Building your app with this version of Xcode and the iOS SDK allows your app to access the latest APIs and native frameworks.</p><p>You can review API changes in the release notes for each iOS SDK version. (For iOS SDK 18, you can view them <a href="https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-18-release-notes">here</a>.) These notes describe which APIs have been deprecated, removed, or added, as well as resolved issues.</p><p>Similarly to API changes in Android, if your app uses an API that has been removed in iOS 18, it will crash when attempting to call that removed API. To handle such changes, you can perform API availability checks in your code. Learn more about adopting new API features in iOS <a href="https://developer.apple.com/tutorials/app-dev-training/adopting-new-api-features">here</a>.</p><h4>💐 Privacy changes?</h4><p>Some changes are related to privacy. Google and Apple are enhancing privacy and security in their OSes and sometimes the OS behaviour could be changed for those enhancements.</p><p>An example of privacy related change would be package visibility change in Android 11, and it started to require you to add `&lt;query&gt;` entries in `AndroidManifest.xml` file if your app check if certain packages or apps are installed in the system. For example, if your app checks if apps that handle SMS are installed in the system, you need to explicitly mention about that in the android manifest file. If you didn’t do that, the results you get when you check about available apps in the system, are not as expected although it worked fine before Android 11. More about package visibility in Android 11 <a href="https://developer.android.com/training/package-visibility">here</a>.</p><h4>💐 Changes for device hardware</h4><p>Some changes in OSes are due to the evolution of hardware in devices. In near future, some of the new Android devices will come with 16 KB page size for memory which really increases memory related performance in mobile devices. To make your app works on such devices, you need to recompile native packages or libraries you use in your project so that it is configured and aligned to work on 16 KB page size memory, then rebuild the app.</p><p>But don’t worry. As of writing this article (Mar 2025), there is no devices configured with 16 KB page size in the market, those new devices will certainly have Android 16, and Android 16 has a compatibility mode where it allows apps configured to work on 4KB page size, to run on devices configured with 16 KB page size.</p><h4>💐 <strong>Two Types of Behavior Changes in Android</strong></h4><p>Android introduces two types of behavior changes with each OS update:</p><h4>1. Changes That Affect Only Apps Targeting a Specific Android Version</h4><p>Before discussing this type of change, it’s important to understand the concept of targetSdk in Android. In your build.gradle file, you can specify a targetSdk value. For example, if targetSdk is set to 36, it means your app has been tested on Android 16 (API level 36) and is officially targeting that version. However, your app will still run on other Android versions as well.</p><p>Additionally, the minSdk value in build.gradle defines the minimum Android version your app supports. The Android system ensures that your app can only be installed on devices running this version or higher.</p><p>Now, when an Android OS version introduces behavior changes that apply only to apps targeting that version, your app will only be affected if it explicitly targets that OS version (e.g., Android 16 in this case). If your app targets Android 15 instead, these changes will not be applied, even when running on an Android 16 device.</p><h4>2. Changes That Affect All Apps, Regardless of Their Target Version</h4><p>Some behavior changes in a new Android version apply to all apps, regardless of whether they target that OS version. For instance, even if your app targets Android 15 instead of Android 16, these changes will still take effect when your app runs on an Android 16 device.</p><h4>How to Stay Informed About These Changes</h4><p>For every Android OS and SDK release, Google publishes two key articles:</p><ul><li><a href="https://developer.android.com/about/versions/15/behavior-changes-15">One covering changes that affect only apps targeting the new OS version</a></li><li><a href="https://developer.android.com/about/versions/15/behavior-changes-all">Another covering changes that impact all apps</a></li></ul><p>By reviewing these documents, you can identify which features of your app may be affected and what adjustments you need to make.</p><h4>Behavior Changes in iOS</h4><p>Similarly, Apple publishes release notes for every iOS SDK update. These notes detail API changes, including resolved issues, deprecated APIs, and removed APIs. Just like in Android, reviewing these notes helps you determine which parts of your app need testing or modification to ensure compatibility with the latest iOS version.</p><h4>💐 How to adapt your app as per those changes and make sure it works as expected on those new OSes?</h4><p>Fortunately, Android and iOS apps are generally forward compatible to some extent which means your app built using current SDK, APIs, native framework (in iOS) / AndroidX libraries (in Android) is very likely to keep working on new OS versions. Apple and Google don’t deprecate APIs or introduce behavior changes frequently. They do them only when they have no other choices for security and robustness of the OS and SDK.</p><p>In the next section, we will explore OS release schedule and strategies to ensure our apps are 100% compatible with new OSes.</p><h4>💐 Android os release schedule</h4><p>As of writing this article, the upcoming Android OS release is 16 and the release schedule of the OS, SDK, and related components looks like this:<br><br><strong>Developer preview 1: Nov 2024<br></strong>Early baseline build focused on developer feedback, with some new features, APIs, and behavior changes.</p><p><strong>Developer preview 2: Dec 2024<br></strong>Incremental update with additional features, APIs, and behavior changes.</p><p><strong>Beta 1: Jan 2025<br></strong>Initial beta-quality release, over-the-air update to early adopters who enroll in Android Beta.</p><p><strong>Beta 2: Feb 2025<br></strong>Incremental Beta-quality release.</p><p><strong>Beta 3: Mar 2025<br></strong>First platform stability milestone including final APIs and behaviors. Play publishing also opens.</p><p><strong>Beta 4: Apr / May 2025<br></strong>Near-final builds for final testing.</p><p><strong>Final release: Jun 2025<br></strong>Android 16 release to AOSP and ecosystem.</p><p>Learn more about the schedule in Development section of <a href="https://en.m.wikipedia.org/wiki/Android_16">this</a> Wikipedia article.</p><h4>💐 Migration strategy for Android</h4><p>Here is the strategy recommended by Google. We will use Android 16 as an example. A typical migration has two phases, which can be concurrent:</p><p>1. Ensuring app compatibility (by Android 16 final release)<br>2. Targeting the new platform features and APIs (as soon as possible after final release)</p><h4>1. Ensuring app compatibility</h4><p>Firstly, we will care the behavior changes in Android 16 that affect all apps, and make sure our app is compatible with Android 16.</p><p>It’s important to test the functionality of your existing app against Android 16 to ensure a great experience for users updating to the latest version of Android. Some platform changes can affect the way your app behaves, so it’s important to test early and thoroughly and make any needed adjustments to your app.</p><p>You can usually adjust your app and publish an update without needing to change the app’s targetSdkVersion. Similarly, you shouldn’t need to use new APIs or change the app’s compileSdkVersion, although this can depend on the way your app is built and the platform functionality it’s using.</p><p>(Mostly it is fine not to update the compile sdk version when you only wanna adapt your app for compatibility with Android 16, and you don’t start to fully target to Android 16 yet.)</p><p><strong>Get Android 16:</strong><br>Flash an Android 16 system image to your device, or download a system image for the Android emulator.</p><p><strong>Review changes:</strong><br>Review system behavior changes (that affect to all apps) to identify areas where your app might be affected.</p><p><strong>Test:</strong><br>Install your app on your device or emulator, and run tests. Focus on system behavior changes, and work through all app flows.</p><p><strong>Update:</strong><br>Make only the code changes required to adapt to behavior changes or resolve issues. Recompile with the same API level that your app originally targeted — no need to target Android 16.</p><p>By following above steps, your app will be ready on Google Play when Android 16 actually comes to users’ hands. Congratulation! Now your app is compatible with Android 16, and your users who upgraded their devices to Android 16 will keep enjoying your app.</p><p>You’ve already seen the release schedule of the android SDK and related components. So when would be the best time to do above steps, in other words, in which stage of the schedule? In my opinion, it is around beta 3 or 4 release which is 2025 Apr or May in this case. Because around beta 3 or 4, platform becomes stable and the OS you are testing your app on will have almost the same behaviour as the final released OS. But just my opinion and feel free to find a better timing.</p><p>If possible, we should try the SDK since the developer preview stage of the schedule, test our apps and platforms APIs, report feedbacks to Google which is a win-win contribution for both our apps and the Android SDK and related components.</p><h4>2. Targeting the new platform features and APIs</h4><p>Once you’ve published a compatible version of your app, the next step is to add full support for Android 16 by updating its targetSdkVersion and taking advantage of new APIs and capabilities in Android 16. You can make these updates as soon as you’re ready, keeping in mind the Google Play requirements for targeting the new platform.</p><p>As you plan your work to fully support Android 16, review the behavior changes that affect apps targeting Android 16. These targeted behavior changes might cause functional issues you then need to address. In some cases, these changes require significant development, so we recommend learning about and addressing them as early as possible.</p><p>The following steps describe how to fully support Android 16.</p><p><strong>Get Android 16 SDK:</strong><br>Install the latest version of Android Studio preview to build with Android 16. Make sure you have an Android 16 device or emulator. Update your targetSdkVersion and other build configurations.</p><p><strong>Review behavior changes:</strong><br>Review the behavior changes that apply to apps targeting Android 16. Identify areas where your app might be affected, and plan how to support them.</p><p><strong>Check against new privacy changes:</strong><br>Make code and architecture changes needed to support Android 16’s user privacy changes.</p><p><strong>Adopt Android 16 features:</strong><br>Take advantage of Android 16 APIs to bring new features and capabilities to your apps. Recompile for Android 16.</p><p><strong>Test:</strong><br>Test on an Android 16 device or emulator. Focus on areas where behavior changes might affect your app. Try out functionality that uses new APIs. Provide platform and API feedback. Report any platform, API, or third-party SDK issues.</p><p><strong>Final update:</strong><br>Once Android 16 APIs are final, update your targetSdkVersion and other build configurations again, make any additional updates, and test your app.</p><p><strong>Publish:</strong><br>Sign, upload, and publish your updated Android App Bundle or APK.</p><p>Congratulation! Now your app fully supports Android 16.</p><p>For Flutter apps, you know they access native features of OSes through plugins. So the authors of plugins are recommended to follow above steps, migrate the plugins as needed to target the latest Android OS, and release new versions of plugins for Flutter developers.</p><p>As Flutter devs, you are supposed to follow above steps as well. But you can’t do modifications when the OS change is related to platform’s framework APIs since Flutter apps can’t access those APIs directly. So please follow above steps, when you found out that some features of your app get impacted by the OS changes, and the migration must be done at the plugins’ side, you may inform the plugin author, watch for the new version release of the plugin, rebuild your app, and submit to Google Play.</p><p>(Some of the contents in this section are copied from <a href="https://developer.android.com/about/versions/16/migration">this</a> official migration guide from Google)</p><h4>💐 Release schedule and migration strategy for iOS SDK</h4><p>Apple yearly releases a new version of iOS, SDK, and related components like iOS simulator in this schedule.</p><p><strong>June:</strong> They introduce iOS new version in WWDC, and release a developer beta for OS, SDK and related components. If possible, we should test our app against the components in this phase or as early as possible, and provide feedback to Apple.<br><strong>July:</strong> They release a public beta.<br><strong>September:</strong> They release a Release Candidate version of components one week before the public release. Then the new iOS is released to public. New iPhone models with the latest iOS installed, come to the market.</p><p>My opinionated strategy for the migration is similar to that in Android. We firstly review the release notes of the new iOS SDK, and see if any API that our apps use, are deprecated or removed in this version. If yes, we need to adapt our app. We can test our app on the beta version of iOS simulator with the latest iOS, to see if it keeps working perfectly on the new OS. To do that, we can install multiple versions of xcode, iOS SDK, and iOS simulator in our Mac for the purpose of using beta versions of components while keeping stable version of components for normal builds and releases of our apps.</p><p>Around August, we should adapt our apps as per the API changes in the new SDK using the beta version, and be ready. Firstly, test your app on IOS beta version (simulator or real device). If a feature doesn’t work due to a removed API or a behavior change, adapt your app to use the new API which replaces the old deprecated API, test and rollout to App Store.</p><p>Apple usually gives us enough time for adopting the new APIs. They do not remove an API suddenly like “hey, suprise!” :D. For example, say an API is deprecated in IOS 26, that API usually remains available for use up until a version like IOS 30 for instance. If they decide to remove it on IOS 30, the new API which replaces the old one is already available since IOS 26. At that time of IOS 30, we can test our app on IOS 30, see the feature related to the old API does not work, and adapt it to use the new API instead of the deprecated API.</p><p>As Flutter plugin authors, they are supposed to follow above steps as well. They should adapt their plugins if they are affected by the API changes, and then release the updated version of the plugins before Sep when the final IOS version is released to public.</p><p>As Flutter app developers, when they follow above strategy and test their app on beta version of OS and identify some plugins need adaptation due to the API changes, they should inform the plugin authors about that.</p><h4>💐 Too long; didn’t read?</h4><p>No problem, here is a brief summary on how to ensure the compatibility.</p><p>Around one month before final release of the OS, grab a simulator, test the app on it, fix if needed, and ship it to App/Play Store before the OS arrive to users hand on the following month. That’s for compatibility with new OS. For adopting new OS features in Android, bump target sdk version in build.gradle file, implement and test it. For IOS, there is no such target sdk version like Android does. You auto target the new OS if you use latest version of xcode.</p><h4>💐 Outro</h4><p>It’s been a long article and congratulations if you have read til this point. Having above knowledge help you proactively prepare your apps for new OS versions and ensure your app compatibility with new OSes. That creates a seamless and satisfied user experience for your users.</p><p>If you would like to discuss more about this kind of topics, you can reach out to me via <a href="https://www.linkedin.com/in/hein-sek/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5481e94547" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good ways to learn Automated Testing in Flutter]]></title>
            <link>https://medium.com/@heynxsehhz/good-ways-to-learn-automated-testing-in-flutter-8fd9e751463f?source=rss-55be615b3f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fd9e751463f</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[widget-testing]]></category>
            <category><![CDATA[automated-testing]]></category>
            <dc:creator><![CDATA[Hein Sek]]></dc:creator>
            <pubDate>Wed, 08 Nov 2023 15:13:23 GMT</pubDate>
            <atom:updated>2025-12-28T03:12:50.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L_FbC1RHTXFcX4oj" /><figcaption>Photo by <a href="https://unsplash.com/@agk42?utm_source=medium&amp;utm_medium=referral">Alex Knight</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article describes the approach I used for learning Automated Testing in Flutter. This is my opinion and feel free to find better ways which fit to your learning style. So let’s get started.</p><p><strong>Wait, what is automated testing, btw?</strong><br>- It is instructing the computer to test behaviour of the app by writing test codes.<br>- It is not testing the app manually.<br>- Automating the testing.<br>- We just have to run tests and can see if tests are passed or failed.</p><p>Okay now let’s move to steps.</p><p><strong>Step 1</strong><br>For getting the fundamental knowledge of how to do Automated testing, <a href="https://youtube.com/playlist?list=PLprI2satkVdFwpxo_bjFkCxXz5RluG8FY&amp;si=PKxWqUyaWjpWrHkU">this free online course by VGV</a> is totally helpful. Try to have those knowledge.</p><p><strong>Step 2</strong><br>Then you should read tests in <a href="https://github.com/felangel/bloc/tree/master/examples/flutter_weather">this Weather app project</a> (it’s flutter_bloc library’s tutorial). If you are not familiar with bloc pattern, you might find another project which has tests and which is pretty big like containing REST API calls.</p><p>Reading tests of such projects help you understand what you should test, how you can write tests, what you could do for testing, which are the required knowledge for doing automated testing.</p><p><strong>Step 3</strong><br>Now, you have pretty enough knowledge about how to do testing. The next step you should do is adding tests in the project you are currently working. It may be the project from your full time job or whatever. Write tests in that project. You will face various challenges, problems, and errors.</p><p>But don’t worry, things are that difficult only on the very time of writing tests. Just try to get some required knowledge, and you will be able to solve those problems and add tests to your projects successfully.</p><p>In case you found out that it is super difficult or almost impossible to write tests for the project you are currently working on, it is just because the codes are simply not testable due to several reasons like poor architecture, the developer who wrote codes without techniques like dependency injection. In that case, it is better to create another simple project which includes features like REST API calls, local database, and has a well testable architecture, and write tests in that project which cover all important behaviors of the app.</p><p>Starting from 2025, AI models are good enough to generate tests codes for your project (if your project architecture and codes are testable, of course :D). Thanks to those AI for writing test codes where syntax are difficult to remember, and you get write a bit of some boring boilerplate-like codes. So when you can write tests yourself, you can ask AI to write them for you. When you have written enough tests (like 90% line coverage) for your project (maybe work project or hobby project), I think you’re good to go.</p><p><strong>Required knowledge for writing tests</strong><br>To be able to write complex widget tests and other types of tests, you need to have knowledge about these things:</p><p><strong>Codebase</strong><br>Understand well about your codebase. Say you wanna write tests for the login page for example, you need to know which dependencies the login page depends on. In other words, make sure you have read 100% of the code lines of your codebase.</p><p>Sometimes, there might be a dependency that a screen depends on, in a place of the codebase that you haven’t ever read in your life, and if you didn’t arrange for the dependency in writing some complex widget tests for that screen, the tests will be failed.</p><p><strong>Flutter framework</strong><br>In writing a widget test, it is testing just the widget tree, and not actually running the app on device. And so, if you didn’t include Directionality widget like MaterialApp for example as the parent widget of the widget that is gonna be tested, it shows you an error. Having the strong knowledge about how the framework works really help you debug the test codes, and solve the problems you face in writing tests.</p><p><strong>Test framework APIs</strong><br>Make sure you have the overall knowledge about the packages used in writing tests such as flutter_test, and functionalities or APIs provided by those packages such as how methods like pump, pumpAndSettle, work under the hood (you usually need to play a lot with those methods in writing widget tests, and if you don’t know well about it, you will see failing tests), setUp, setUpAll, tearDown, tearDownAll, CommonFinder, Matcher. Having such knowledge help you wirte tests successfully and master writing tests.</p><p><strong>Mock package APIs</strong><br>We usually have to use packages like mocktail, mockito for mocking behaviors. You need to read the documentation of the mock package you use carefully. Only if you do so, you will be able to successfully mock as you expected. Otherwise, you will see errors and bugs related mocking, and you will fail to mock.</p><p>(Note: if you haven’t learned much about automated testing, you might find some difficulties in reading the words in the next section, and might not understand some parts. So you may come here again after following the step 1 and 2 that I mentioned above. But it’s totally fine to continue reading to get some more ideas.)</p><p><strong>Tips for writing automated tests</strong></p><p><strong>Write clean and readable test codes:</strong><br>You need to keep test codes clean by following clean codes principles and techniques.</p><p>If it is not clean, it is just equivalent to having no tests. How? Having bad or dirty test codes -&gt; other develpers can’t read or understand tests -&gt; they are not able to add new tests -&gt; having no confidence on the codes we write or modify -&gt; we need to rely 100% on manual testing -&gt; now the same pain points we usually get if we don’t have tests, emerge. (eg. not dare refactor, having to spend so much resources for manual testing after modifying or refactoring codes)</p><p><strong>So how to write clean tests?</strong></p><p><strong>Some tips for writing clean tests</strong><br>- the goal of the test should be clear,<br>- follow Single Responsibility Principle (SRP). One testcase should test only one thing or one behavior. Do not test or verify two behaviors in a single test case. If a test follows SRP, it has only one reason to change. Since it focuses on only one thing, it gets to change only when that one thing changes.<br>- testcases should be isolated, and should not be coupled to other testcases so that the order in which a test is executed doesn’t affect whether it will pass. <br>- avoid making super large test files which are difficult to manage. Since the file is large and long, say it has 2000 lines of codes, we don’t usually wanna read and edit such files. Even jumping between lines by scrolling up and down take efforts. Make only pretty small and easy-to-read test files. For keeping such short files, the tip in the next section is really helpful.<br>- Robot pattern in writing integration tests is helpful. (<a href="https://verygood.ventures/blog/robot-testing-in-flutter">link</a>). Initially, you might be writing only units and widgets tests. You may move to integration or end to end test as next steps.</p><p><strong>Some tips for designing codes to be testable</strong><br>- avoid static methods and variables for some classes which need to be mocked. Say you have a utility class called ConnectivityUtil which has a static method that check if the device has internet connection or not. And when you write a widget test, you need to mock it so that it always return the status of “is connected to internet?”. You can’t mock that behavior if you use static method.<br>- for better experience of writing widget tests, use the style “stateless widgets wrapped in the stateful widget”. That style is explained in <a href="https://youtu.be/bj-oMYyLZEY?si=HdUk-YBXEm5o0idn">this YouTube video</a> (skip to 39:00). You should watch and learn about testing from that video if you could make time. It contains some valuable concepts about testing.</p><p>You can find that style in the weather app I mentioned above, as well. There is a WeatherPage which interact with the cubit called WeatherCubit. That page wrap seperate widgets like WeatherEmpty(), WeatherLoading(), WeatherPopulated(), WeatherError().</p><p>By doing like that, we can test the main WeatherPage and those small widgets separately, which help us make smaller test files, and avoid large test files. And it improve test execution speed because it reduce the number of unnecessary testcases in WeatherPage (we will have large number of testcases in WeatherPage if we put all UIs in WeatherPage widget and didn’t seperate some UIs into seperated widgets like WeatherEmpty(), WeatherLoading(), Say we have to do a pretty expensive setup before every testcase, the larger the number of testcases in WeatherPage, the more time it takes for running tests.)</p><p>I will add more tips whenever I get more lessons and experience of writing tests.</p><p>(At the time of writing this article, I don’t have the strong exprience about integration and golden tests, and I am just applying unit and widgets testing in my project which still give me some level of confidence. So I can’t share about my experience of wrting those tests right now.)</p><p><strong>Some good resources about testing</strong><br>You should listen to <a href="https://pca.st/episode/2137c9dc-e901-4b99-ba07-38560109cd52">this podcast of Flutter 101</a> if you would like to know about the experience of writing unit, widget and integration tests.</p><p><a href="https://verygood.ventures/blog/guide-to-flutter-testing">Flutter testing: A very good guide [10 Insights]</a></p><p><a href="https://verygood.ventures/blog/flutter-testing-resources#packages-for-tests">Flutter testing resources</a></p><p>Happy testing!</p><p><em>Contact: </em><a href="https://www.linkedin.com/in/hein-sek/"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fd9e751463f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>