Open Zhelyazko opened 3 years ago
Sorry I don't think we have any documentation on this class, but https://dagger.dev/api/latest/dagger/hilt/android/testing/OnComponentReadyRunner.OnComponentReadyListener.html is probably what you want. You can register that with OnComponentReadyRunner
and we'll call you back when the component is ready to use.
That should solve most test rule cases, though if you need it exactly at that time in the rule and cannot delay then you might still have a problem.
I added the documentation label since we should have docs on that class.
I'm migrating a big app from Dagger to Hilt, where we have a few JUnit Rules that had an
@Inject
annotated fields in them - used for things like deleting test data from Room Database, clearing some state from internal classes etc. Now when migrating to Hilt, there doesn't seem to be a way to inject an instance of let's say Room DB into a Rule.I have a setup like this one:
I also updated our Rules so that they have something like this:
When I run our tests, I receive the following error:
Is it possible somehow to inject dependencies into Test Rules? The general recommendation from Hilt is to move our logic away from Custom Application class into Rules, but without being able to inject dependencies, we can't do that.