Closed p4r4n01d closed 6 years ago
DaggerMock can override only not abstract modules and ContributesAndroidInjector
are not supported. But you can try to create a new module (not abstract) with the objects you want to override.
Does DaggerMock support the new dagger-android library?
@RoRoche the new dagger-android library is not supported in current version but I am working to support it (at least for replacing objects defined in application component). I hope I'll release a new release soon.
@RoRoche could you give me a link to the new dagger library your referring to. Maybe i can help
I've been using it with goggles dagger2 . I't seems ok
From: Romain Rochegude notifications@github.com Sent: Thursday, August 31, 2017 10:14:50 PM To: fabioCollini/DaggerMock Cc: j2emanue; Mention Subject: Re: [fabioCollini/DaggerMock] @ContributesAndroidInjector module support (#47)
@j2emanuehttps://github.com/j2emanue https://google.github.io/dagger/android.html
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/fabioCollini/DaggerMock/issues/47#issuecomment-326327549, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEuvOk6VJGflWO-tgLdXtfkKIwe7tG7_ks5sds3qgaJpZM4N-7cN.
I have pushed a new version to support Dagger Android (you can try it using version 0.7.1-beta1). You must add an invocation to method customizeBuilder
to set the application, an example is available here.
In this version Dagger Android is supported in Espresso test to replace objects defined in Application component, I'll continue to investigate to find a way to support it in JUnit tests and for subcomponents and dependent components.
I am using the dagger2 android injector helper classes and would like to provide mocks of some objects in the ApplicationModule (not shown). However, the module is abstract as dagger generates the activity injector code so I cannot create an instance of the module in my mock TestRule to call the constructor of DaggerMock. Is there a way to mock this without adding an extra subcomponent?
ApplicationModule.java
Here is my application component, which uses a builder
ApplicationComponent.java
Here is the application class.
TheApplication.java