No Mocks Allowed

Disclaimer: It has been brought to my attention the title can be seen as a click bait. That wasn’t my intention and I’m sorry. I wanted to reference the Fallout game series and the No Mutants Allowed community. Testable code plays a crucial role in app development. When we neglect designing code for testability, we often resort to using a mock library (such as Mockito Kotlin, also know as “auto-mockers”) as a mean to achieve test coverage....

June 28, 2023

Injection Points

Android has made significant progress in becoming a DI-Friendly Framework. Throughout the years, new APIs like AppComponentFactory and FragmentFactory have been introduced, allowing apps to incorporate their own custom constructors and facilitating the development of testable code. The purpose of this article is to highlight some of the Android APIs that are utilised behind the scenes. By exploring these APIs, developers can gain a better understanding of the underlying mechanisms employed by popular libraries (such as Dagger Hilt and Koin Android)....

June 2, 2023

Namespace for Extension Functions

A few weeks ago, I had to create an extension function - a usual task for any Kotlin developer. But there were a few limitations: The receiver was a common type, polluted with too many methods. The extension function was only relevant to my feature package. Creating a Gradle module was out of scope. Introducing a new type to hold the function felt like too much. Kotlin doesn’t support package-private, yet....

March 25, 2023

Deep Models

Modeling is a critical task in Software Development: good models reduce the risk of bugs, increase readability and improve maintainability. However, we can often see developers focusing on “How can I code this?”, and they are done with their task when they find a way to code it. This inherently reduces the domain modeling to the abuse of primitives and shallow design where any inconsistent state is allowed. To better explain, let’s consider the hypothetical requirements:...

October 7, 2021

Humble Views, Proud ViewModels

The Android Community has long advocated that Activities and Fragments were views - but this perception has changed over time. For good. Let’s dive deep into how to design views and view models, how they wire to a LifecycleOwner, and how this can positively impact your’s app testability. To better describe how to build humble views we will be developing an elementary Sign-Up form with an email, a password text field and two buttons: a cancel that pops the user’s back stack and a sign up that creates an account and moves the user to the home screen....

February 1, 2021

Naming Factory Methods

When talking about Factory Methods, extension functions tend to be favored in Kotlin - but it might be a challenge to name these functions in a discoverable way without polluting your project’s namespace. A good source of inspiration is Kotlin’s Standard library: it contains many examples we can use as a base when deciding how to design a function. Wrapping an instance If you intend to get a given instance and adapt to one different object to follow another contract, for example, creating a ViewModelProvider....

February 1, 2020