I have this setup of component plus module, say FooComponent and FooModule, which provides a simple singleton, which needs to be replaced in one of the test variants. Therefore, in the variant I have instead FooTestComponent, which inherits FooComponent, but its @Modules annotation points to another module instead, FooTestModule. So far FooModule provides only one dependency, so no problem with that.
However, as dependencies that need not to be replaced in tests are added to FooModule, I see myself forced to replicate all of the methods to provide them in FooTestModule too since they can't be extracted to a parent abstract module that both FooModule and FooTestModule inherit from. What is the way to avoid this duplication?
The Dagger 2 User's Guide Testing Section contains advice for this very scenario.
To summarize the advice there:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With