In MVVM, ViewModel exposes streams of events to which the Views can bind. Generally, we use LiveData inside ViewModel and the view can observe for live data changes.

When it comes to unit testing for ViewModel, we create an observer, passes that observer to Live data, and verify its changed event.

viewModel.sessionSubmitLiveData.observeForever(dataObserver)
viewModel.submitSession(submitRequest)
verify(dataObserver).onChanged(data)

You can explore this approach in the below article.

If we want to assert data, then how can we do that?

Photo by bruce mars on Unsplash

Let take an example, we make a simple API call, we show loading, then hide loading based on API event, then show data/error. So we have 3 states to represent. Thanks to Kotlin, we have sealed class

Loading, Error, Success


In my previous articles on unit testing, I have talked about ViewModel, Usecase, Repository testing using JUnit & Mockito. Today I am going to explore about Spek framework for unit testing.

What is Spek?

Spek is a Kotlin-based Specification Testing framework. Spek is written in Kotlin and specifications or tests we write will be in Kotlin. However, our SUT (System Under Test) can be Java or Kotlin.

Currently, Spek is implemented as a JUnit Platform TestEngine. This means that we can easily plug it into any project that already uses JUnit 5.

This allows us to easily define specifications in a clear, understandable…


Recently I was working on Google Maps markers and I had to handle multiple marker states like Loading, Pickup, Destination, and other information on the markers. Markers indicate single locations on the map. We can customize markers by inflating our own layout and based on our use-cases.

Here are some demo examples where custom makers are useful. The most common examples are markers on cab services. We have seen ETA on the marker, Location, direction, etc on the marker.

If you want to skip this then please use the below link for demo.

lets take a simple example where we…


Photo by Van Tay Media on Unsplash

This is part 3 of the android interview experience. You can also read my previous articles on android interviews.

Android Interview Questions Part 1

Android Interview Questions Part 2

  1. What is the difference between Val, var, const Val?
  2. Internal keyword in kotlin?
  3. What is the ViewModel factory and constructor of view model?
  4. ViewModel with a single activity and multiple activities?
  5. Use of Mediator live data?
  6. MVVM vs MVP?
  7. Task affinity?
  8. Can GSP work without the internet?
  9. Lambda Expression Vs Anonymous class?
  10. Thread.sleep() & wait()?
  11. What are functional interfaces?

Recommended: Please solve it first, before moving on to the solution.

There…


Photo by Maranda Vandergriff on Unsplash

In my personal opinion, a good way for preparing any kind of interview is that after the interview gets over, note down all the questions that were asked in the interview and try to find the solution for the questions that you were not able to answer at the interview time. So I am going to share a few of the questions.

You can also read a few questions from my previous article.

  1. How to execute 5 API calls parallel and once all completed do the next task?
  2. Flatmap vs compose?
  3. What will happen if you don’t override toEquals() method?


Sometimes while developing an application, we have encountered a situation like based on some logic, we have to render some new view in the layout that is rarely used. A general approach for this is to make View visibility GONE/VISIBLE.

So always inflating this rarely used view in a layout, is not a good idea and also it impacts the rendering of the layout.

So what to do in this case?


Recently I was working on Google Maps with custom marker layout and I was inflating custom marker layout and creating bitmap from that layout as MarkerOptions accepts bitmap. So layout inflation + bitmap generation was happening in main-thread (fragment). This could create unresponsiveness and jank.

Layout Inflation

so, I search for this scenario and found AsyncLayoutInflater.

What is AsyncLayoutInflater?

Helper class for inflating layouts asynchronously.

When to use AsyncLayoutInflater?

This is intended for parts of the UI that are created lazily or in response to user interactions. …


The most common way to change directory from the command line is cd
How do we change the directory?


Many of us already used it or some might be using it. Let’s explore more about data class in Kotlin.

What is a data class?

Data class is used to hold data/state and contains standard functionality.
In Kotlin, data keyword is used to declare a class as a data class.

How to create data classes in Kotlin?

  1. You need to append the class with the keyword data
    data class Person(val name:String)
  2. The primary constructor needs to have at least one parameter.
    data class Person() this is invalid declaration of data class
  3. Each parameter of the primary constructor must have val/var…


In this article, we are going to learn how to use these 5 scope functions. Many of us have already used these functions. So what we need to learn about them

How we should use them?
and when we should use them?

The way they perform, sometimes become the cause of confusion.

let's learn more about them. We will take the example of webview.
so we will set few properties of the webview.

with
It is convenient when you have to call multiple different methods on the same object. Instead of repeating the variable containing this object on each line…

Kishan Maurya

Android Engineer | OlaElectric | https://droiddevgeeks.github.io

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