Replies: 4 comments
-
Does https://github.com/evant/kotlin-inject/blob/main/docs/testing.md answer your question? The README sample was written before that and probably could be updated with a more realistic usecase. |
Beta Was this translation helpful? Give feedback.
-
It does not. These are the classes in testing.md, they have no dependencies, unlike the example I've given above. @get:Provides val accountService: AccountService = FakeAccountService(),
@get:Provides val userService: UserService = FakeUserService(), |
Beta Was this translation helpful? Give feedback.
-
You want to inject into your test fakes? There's nothing stopping you from declaring extra provides in TestApplicationComponent. |
Beta Was this translation helpful? Give feedback.
-
@evant I'm still unable to understand. @Component abstract class AppComponent(@Component val network: NetworkComponent) |
Beta Was this translation helpful? Give feedback.
-
Here's a modified version of the component inheritance example from README.md.
Notice that the
api()
functions inRealNetworkComponent
andTestNetworkComponent
have different dependencies (DepA
andDepB
). This will obviously not compile. But in real world situations test classes and prod classes can have different dependencies. How do we achieve this using kotlin-inject?One solution would be to add all the dependencies to the
NetworkComponent.api
function signature.and then the sub classes can simply ignore the dependency that they don't need. This would work but it feels like a hacky workaround rather than a proper solution. And there might be situations where
DepA
will be present in main src whileDepB
will be present in test src.So what would be the proper solution to this?
Beta Was this translation helpful? Give feedback.
All reactions