Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use AndroidInjection the mock doesn't work #70

Open
charleston10 opened this issue Feb 21, 2018 · 3 comments
Open

When I use AndroidInjection the mock doesn't work #70

charleston10 opened this issue Feb 21, 2018 · 3 comments

Comments

@charleston10
Copy link

charleston10 commented Feb 21, 2018

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

@fabioCollini
Copy link
Owner

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?

@sarmadali20
Copy link

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

@fabioCollini
Copy link
Owner

Hi, what do you mean with ActivityBuilder? Can you add more informations to reproduce this problem?
Thanks for your report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants