DaggerMock
DaggerMock copied to clipboard
When I use AndroidInjection the mock doesn't work
When I use AndroidInjection the mock doesn't t work Example
/* FooActivity */
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)
}
When I inject by AppComponent the mock is work
/* AppComponent */
...
interface AppComponent {
fun inject(fooActivity: FooActivity)
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): Builder
fun appModule(appModule: AppModule): Builder
fun networkModule(networkModule: NetworkModule): Builder
fun build(): AppComponent
}
...
My Rule
val app: App get() = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as App
fun espressoDaggerMockRule() = DaggerMock.rule<AppComponent>(
AppModule(app),
MockNetworkModule() //doesn't use this class when I use AndroidInjection
) {
provides(MockNetworkModule())
set { component -> app.component = component; }
customizeBuilder<AppComponent.Builder> { it.application(app) }
}
daggermock: 0.8.4 dagger: 2.11
Hi, are you using something to open the classes in the tests? You can find more info here: https://github.com/fabioCollini/DaggerMock#kotlin-support
Can you explain better the problem? Do you get any errors?
Were u able to fix this, I can't seem to get the mocks working no build or runtime errors. I have a mix for kotlin and java. I think the problem is ModuleOverrider can't understand ActivityBuilder
Hi, what do you mean with ActivityBuilder? Can you add more informations to reproduce this problem?
Thanks for your report