Blog Posts
Writing Screenshot Tests with Paparazzi
Introduction Screenshot testing is one of the most powerful ways to make sure your UI remains looking the same over time. With screenshot testing, we aren’t only checking if the UI elements are present on the screen, but also if they are positioned well, and if they look as they should.
What’s good about the Screenshot testing lately is that it gets fast, stable and reliable way to test UI. In terms of Android, a bunch of frameworks are available lately, and one of them is Paparazzi
Blog Posts
State vs. Behaviour Verification
Suppose we have the following interface:
interface Validator { fun validate(query: String): Boolean } and suppose it’s being used as a collaborator in a few places:
class FindItems( val validator: Validator, val repository: Repository ) { fun search(keyword: String) { if (validator.validate(keyword)) { repository.findItemsContaining(keyword) } } } class DeleteItems( val validator: Validator, val repository: Repository ) { fun deleteMatches(value: String) { if (validator.validate(value)) { repository.deleteItemsMatching(value) } } } Of course, we would have some tests for these functionalities, which might look something like this respectively:
Blog Posts
The Sequence Diagram
⚠️ Disclaimer Any kinds of diagrams have nothing to do with TDD at all. We find the diagrams handy when we want to visualize, explain, teach, or learn something. That’s all. It’s a drawing on a sheet of paper that we throw afterward. We don’t keep the diagrams around; we don’t maintain them. That’d be a massive waste of time.
Sequence Diagram Example
What’s this Sequence Diagram thingy? As mentioned in the disclaimer, the sequence diagram is a tool we can use to visualize an approximation of where we want to go when working on the unit in question.
Blog Posts
Improving Design - Separating responsibilities
Let’s take a look at the following piece of code:
fun search(query: String): List<String> { val allItems: List<String> = ExternalSystem.fetchAllItems() val filtered = allItems.filter { it.contains(query) } val reordered = filtered.sortedWith(object : Comparator<String> { override fun compare(lhs: String, rhs: String): Int { if (lhs == query) { return -1 } else if (rhs == query) { return 0 } return lhs.compareTo(rhs) } }) return reordered } From a behavioral point of view, this code has no problems.
Blog Posts
Refactoring Legacy Code
Intro Quite often in software development, we come to a point where we have to alter some code, whether to make it easier to read and understand or to add a new feature.
Recently a friend of mine posted a piece of code in a public Slack channel, and he asked for resources that would help him improve not only that particular code but any legacy code in general. I’m very thankful that he asked that because I took it as a motivation to record a series of screencast videos where I explain and demonstrate a bunch of techniques that everyone can learn and use in their daily job.
Blog Posts
Setting up Koin for Android UI testing
Problem definition Recently I’ve come to a problem running my UI tests because of a DefinitionOverrideException. That’s an exception thrown by the Koin library when we have a duplicated definition for a particular type. The way we use Koin on Android is by starting the container in the onCreate() method of the Application class and loading the relevant modules into the container. Here is how it may look like:
Blog Posts
On Test-Driven Development
A quick overview in our industry I’m in the IT industry, particularly in Android for roughly 10 years now, and one thing I can tell with great confidence is that this industry moves incredibly fast. Looking back all these years, it’s been an extraordinary evolution of the OS itself, as well as the community around it. However, sometimes it feels like our industry lacks a lot of good practices and discipline in the development process, a lack of professionalism.
Blog Posts
Android KTX
Intro Android KTX is an open source library or set of functionalities designed to make the Android development with Kotlin even more pleasant. The abbreviation KTX stands for Kotlin Extensions, so this library is basically a set of extension functions, extension properties and other top-level functions. In this article, we take a look at what’s inside this library and how we can take advantage of it. This library’s goal is not to add new features to the existing Android APIs, but rather make those APIs easier to use by leveraging the features of the Kotlin language.
Blog Posts
Android Navigation Arch Component
About On the Google IO 2018 event, there was an announcement of JetPack — a set of libraries to help and boost the Android development. These libraries are bringing the development of the essential parts of an application to a completely new level. By essential parts I mean things like handling configuration change, persisting data, executing operations in the background and so on. Some of those libraries were announced at Google IO 2017, and by now are having a stable release, and some of them are completely new.
Blog Posts
Testing Android UI with pleasure
Intro Although it should be very clear by now, testing is a very important part of the software development. Tests are, in a way, a construction around the software, which provides confidence for altering its structure (mostly to improve it) while being sure the behaviour stays the same.
This article is focused mainly on the UI tests in an Android application. Traditionally, testing the UI was done by running a mocked backend on the same machine where the device/emulator is exercising the UI tests.