DaggerMock
DaggerMock copied to clipboard
How would one work with subcomponents?
Let's say I have an AppComponent, which has a subcomponent UserComponent, which in turn has a ProfileComponent, each with sub/modules:
@AppScope
@Component(modules={AppModule.class, NetworkModule.class})
interface AppComponent {
UserComponent userComponent(...);
}
@UserScope
@Subcomponent(modules={UserDataModule.class})
interface UserComponent {
ProfileComponent profileComponent(...);
}
@UserProfileScope
@Subcomponent(modules={SomeProfileModule.class})
interface ProfileComponent {
// other subcomponents here
void inject(UserProfileActivity activity);
}
What I'd like is to have an integration test, from the UserProfileActivity onwards. From the examples I'm seeing, they only show how to deal with 1 component or top-level component.
How would I get a reference in this case, to the ProfileComponent, since creating a Rule for it will not cut it, since it has to be created like: appComponent.userComponent(...).profileComponent(...)?
Thinking it has something to do with addComponentDependency
, but unsure how it should work when I have a module (e.g. UserDataModule) with an activity reference in the middle.
Hi, I have some questions to understand better your problem:
- what test are you trying to write? An Espresso test that launch the UserProfileActivity?
- which objects do you wan to to replace with some mocks in the test? Which component are defined in?
- do you get an error if you don't use
addComponentDependency
in a test?