This is a sample to showcase how to write unit test case and UI test case in Android by using JUnit, Espresso and Mockito with RxJava, Android Architecture Component and Dagger2.
Home screen shows users, stored in database in RecyclerView and a floating add button. User can insert into database new user by clicking the floating button.
Dependency injection is accomplished through Dagger2 for both main and test apk build. Custom testInstrumentationRunner is user for testing.
Espresso and Mockito are used for UI test. Test covers the following functionalities:
- Display user list - user list is properly displayed in RecyclerView
- Add user - error message is showing for invalid data.
- Delete user - user list item is remove from RecyclerView
- Select user - display user details.
Room database is used for persistence layer. Room in-memory database is used for tasting persistence layer code.
Mockito and Junit are used for unit test.