Recent 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:
read more
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.
read more
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.
read more
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.
read more
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:
read more