Top
Android, Blog

Testing Dagger 2 with Espresso, Mockito & Robolectric

Dagger 2 brings us @Component and @Module – annotations which imply less boilerplate code, but unfortunately, make our project less testable. In this article, I will show a project, which is using Dagger 2 and is testable with frameworks like Mockito, Espresso or Robolectric.

Anyone who has ever tried testing an Android project that is using Dagger 1 knows, that this is quite possible to override existing modules and replace them with test ones, e.g.:

Dagger 2 brings us @Component and @Module, annotations which imply less boilerplate code, but unfortunately, makes our project less testable. In this article, I’d like to show the project which is using Dagger 2 and is testable with frameworks like Mockito, Espresso or Robolectric.


Complete source code can be found on Droids On Roids Github

Making project

Let's talk about your app

Hi, I am Wojtek. Do you have any questions?
Feel free to get in touch

ESTIMATE PROJECT ➜
Not ready for an estimate?
Attend Product Design Workshop to clarify your vision and prepare the crucial documentation.