Instrumentation Tests with Dagger2, Retrofit2, RxJava2 and MockWebServer — Android
It has been a while since I wrote a blog, I got some time to write about UI testing, which I found useful. When I started writing test cases, I was sure to use DI, mock server response, it took a while to come with a fully functional flow. I’ll share it here step-by-step.
Refer my blog for Unit tests in Android
Unit Tests with Dagger2, Retrofit2, RxJava2 and MockK — Android
Unit Tests are test cases which runs on JVM, used to find bugs in code at the early stages, it is not for the product…
NOTE: Before starting, if you are not familiar with Dagger2, Retrofit2, RxJava2 and Kotlin. Pls, Stop! there are plenty of resources available on the internet, have some knowledge, then continue with this flow.
Step 0: App Demo
It’s a simple app, once you launch, it’ll hit an API call based on the success or failure, we’ll update the text view.
Step 1: MockWebServer
As the name suggests, it mocks your web server. It’s a handy tool from Square.
Step 2: Dagger2
I’ve made a function getAppComponent() in app’s Application class to return DaggerAppComponent,
Step 3: Create Dagger2 Module, TestApplicationModule.kt