Open Tinder-FroWarner opened 5 months ago
@Tinder-FroWarner
Is the view located in the main source set or in a test source set? If the latter, you likely need to add a "testKapt" or "kspTest" configuration.
If not, mind providing a sample project? This is very specific to your setup and I'm inclined to consider this a Hilt configuration issue without something to help easily repro.
Took another look at this. The issue is that BridgeContext inherits from Context, not ContextWrapper, therefore dagger.hilt.android.internal.Contexts
is unable to find the application context here: https://github.com/google/dagger/blob/a8581e0a62b7cb3d1f5a13da26a8f40e22aad3d0/java/dagger/hilt/android/internal/Contexts.java
One option might be to file an issue with the Dagger team to special case layoutlib's BridgeContext, but I could understand that request being turned down. I'll file this as a feature request with the LayoutLib team and see where that goes.
Tracked here: https://issuetracker.google.com/issues/342557695
Thanks for creating the issue with the LayoutLib team @jrodbx! 🙏🏼
Ran into a similar issue when trying to create a snapshot test for a View
that uses Hilt's EntryPointAccessors.fromApplication
to inject something from applicationContext
. I assume it's for a similar reason?
Any thoughts on a possible workaround for the time being? Is it possible to somehow make snapshot tests to mock/"give" them an "application context" or otherwise mock the injected dependency itself? Thanks!
Description
We are working on creating a snapshot test for an Android View with injected dependencies via Dagger/Hilt, but are running into an issue when generating the snapshot if a view is annotated with
@AndroidEntryPoint
.Steps to Reproduce
The following gives an example of the error and setup.
Exception
Example Code
Example of View:
Example of Test:
Expected behavior
Snapshots generate and tests pass.
Actual Behavior
Snapshots only generate and tests pass when commenting out the injected
val
s and@AndroidEntryPoint
i.e.Additional information: