Unit Testing ViewModel

12 Sep 2019

This post describes how to Unit Test the ViewModel in MVVM. If you don’t know what MVVM is, please read Basic MVVM in Android first. Why Write Unit Test? It will help you to structure the code and you can tested it before writing the View. You can also create fake Models and create the View without any need for a connection to a database or a server. You can prevent to break the code in the future.

Read More »

Model Injection using MVVM

03 Sep 2019

This post will handle the Model of MVVM. If you don’t know about View or ViewModel, please read Basic MVVM in Android first. Model as a Singleton The Model of the MVVM is a singleton. In Kotlin you can declare it as an object. But, there are two problems! What if the Model need a reference to the application or other static data? During unit testing the Model has no access to the hardware, like the file system.

Read More »

Basic MVVM in Android

23 Aug 2019

What is MVVM? MVVM stand for View - ViewModel - Model and is a way to divide the software into parts. As you can see in the image above, the View knows the ViewModel interface. But the ViewModel knows nothing about the View. The same is true for the ViewModel, it knows about the Model interface. But the Model knows nothing about the ViewModel. Changing the View do not affect the ViewModel or the Model.

Read More »