How to use hilt for testing in a multi module android project?

179 views Asked by At

I’ve couple of questions when trying to use hilt for testing in a multi-module project:

  1. Say I’ve a feature module which declared some interface and its classes depend upon that interface. The implementation of this interface is provided in the :app module (or any module below :feature) which is not available to feature module. How can I write tests for feature module in the feature module itself? As feature module don’t have binding for that interface, it throws missing binding error. Sure I can provide fake/mock dependencies for them, but what if say I’ve 50 such interfaces whose bindings exist below that feature module? Providing fakes doesn’t look scalable here
  2. How to replace only a single dependency in other module?
  3. If we need to use @UninstallModules for #2, how will you do so when the original dagger module is internal?

I've tried using local dagger module inside @HiltAndroidTest annotated class, but without @UninstallModules, it doesn't work. And I don't have access to original module since it was internal to that gradle module

0

There are 0 answers