Skip to content

DaggerMock rule in Espresso with injected dependencies used in App's onCreate #88

@mariusgherman

Description

@mariusgherman

I want to write an Espresso test and mock dependencies that are also used in Application's onCreate.

I have an app that needs to register lifecycle observers in Application onCreate. The lifecycle observer is an @Inject dependency

public class MyApplication extends Application {
        @Inject
        lateinit var lifecycleObserver: LifecycleObserver

        override fun onCreate() {
            super.onCreate()
            inject()
            ProcessLifecycleOwner.get().getLifecycle().addObserver(lifecycleObserver);
        }
}

What I'm seeing that the DaggerMock rule is created after the App onCreate is called in my Espresso test.

Is there anyway around this, to get my DaggerMock rule created before my Application's onCreate and provide me a mock of lifecycleObserver ?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions