A practical explanation on implementing S.O.L.I.D Principles with perspectives on a real life example.

Single Responsibility Principle

Each function or class should have only 1 responsibility.In below example the loginUser function contains 2 responsibilities

  1. Sign-in user using firebase auth
  2. If error occurs, log by creating and appending a file in catch block.

So in a scenario of making a change for either one you will have to consider any implications which can happen in both code blocks.

So to solve this we take the file creation and logging error responsibility to…


Testing Fragment/Activity interactions with Mockito & Espresso continued.

Let us write a test case for scenario : when user pick on a image, from ImagePickFragment, then we navigate user back to AddShoppingFragment and make sure the image url is available in ViewModel.

We start off by first creating an image picker adapter using recycler view and diffUtils, then we create a fragment factory so to pass constructors to our fragments when needed.

right click on ImagePickerFragment -> generate -> test case -> choose androidTest folder

Testing action image click in ImagePickerFragment which set image url in model view and navigate back to AddShoppingFragment

Since our fragments need constructor parameters which is supplied with the help of fragment factory we need to inject this in our test…


Testing Fragments and Navigation with Dagger HILT

When your test cases grow at a rapid pace , object initialization will become repeated in the @ Before setup(){} function in your test classes, Example: room database.

@Before fun setup(){

database = Room.inMemoryDatabaseBuilder( ApplicationProvider.getApplicationContext(), ShoppingItemDatabase::class.java ).allowMainThreadQueries().build()

dao = database.shoppingDao()

}

A database instance is something that's often needed by several test classes. If you keep doing initialization as shown above for all your test classes, it will create a lot of boilerplate/repetitive code.

That is the reason we use Dependency Injection with Dagger-HILT so every object that’s required is defined in the…


Testing View Model and Repository

For this tutorial i used api from https://pixabay.com/api/docs/ to demonstrate Networking with Retrofit API calls.

I will not go through setting up retrofit and dagger hilt , below i have linked the files to all the setup.

You know by now that test cases have to be fast, but network calls are anything but that. …


In this part we look at testing android components,@Before and @After concepts and how we can test Room DB.

In the previous tutorial we created a function and test case which can run using the JVM inside the test folder, now lets work on another example that requires a context and checks if string from resource file matches with string from user input.

Let’s get started

This time we will create a kotlin class, in this case we will need a instance of this class in our test case. So go ahead and create CompareStrings.kt


What is Android Testing with simple example

This tutorial series will cover all the necessary things you need to know about testing in android using a working example from my github.

  • JUnit / Mockito / Espresso / Google Truth Library
  • TDD with Simple examples
  • Room DB/Retrofit Network using with Pixabay Api
  • Dagger-HILT
  • MVVM
  • Fragments & Navigation

We are required to write test cases in our android apps so that we are able to test code instantly from scratch with single button click on a regular basis.This helps us keep our code bug free most of the time.

Let's get started


A article that will explain and help you understand how you can use Dagger HILT in your next project be it big or small 🙌

What is MVVM?

A simple explanation,It is google's recommended architecture which practices SEPARATION OF CONCERNS , what this means is , every layer (Model / View / ViewModel) is independent from each other.

You should never write all your code in one activity or fragment, to avoid lifecycle related issues. We also do this so that everything is easily testable and readable.

The parent has direct relation to the child, but the child has no direct relation to…


Everything you need to know on coroutines while you wait till your pizza gets delivered.

Implementing coroutines to your android project.

// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'

// Coroutine Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

What is coroutines?

First you need to know what functions and threads are to make sense of coroutines, functions are a set of instructions that give us outputs based on our inputs,threads describes in which context these sequence of instructions should be executed in. …


This article mainly focuses on how OOP theory can be applied on android using Google’s latest language , Kotlin!

The 4 main concepts in OOP are Inheritance,Abstraction,Polymorphism and Encapsulation, The most fundamental reasoning behind using OOP concepts in projects is to allow developers to scale, test and manage their projects efficiently.

Inheritance

All classes in your project which have no defined superclass, inherit from a common superclass called any in kotlin, to make a class inheritable you have to use the keyword open, because by default a class is final and cannot be inheritable. …

Zaid Zakir

I'm always in the lookout to learn new things and become better everyday and do my best to give back to the community which gave me alot when I started.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store