We all know the best practices about developing with Android. It is about using Kotlin, Dagger 2, Retrofit and RxAndroid. But when your architecture is done, the next question is how to write good unit tests.
We will work on an MVP project with Kotlin, Dagger 2, Retrofit and RxAndroid which is based on JSONPlaceholder API to display a list of posts. It currently has no unit test at all.
The source code can be found on the annotationprocessor branch of the Feed-Me project on GitHub.
Once you get the project from GitHub, add a class named
PostPresenterTest in the…
There comes a point in your software developer journey where you realise that unit testing is really important. This especially happens if you want to make sure that your code still works after you do some changes.
In Android, there are two types of tests:
This article focuses on the latter. Espresso testing framework is usually used to automate UI testing with the help of AndroidJUnitRunner test runner. Other libraries also exist such Robolectric.
Firstly, assuming that you have an android project ready, add the below extra gradle dependencies:
Have you ever felt boring when you have to run your app for a small little change to see it is working fine or not?
If yes then, you must try Robolectric, it is a unit testing framework that allows Android applications to be tested on the JVM without an emulator or device.
These are the main features of it:
The (retired) Pub(lication) for Android & Tech, focused on Development