-
Notifications
You must be signed in to change notification settings - Fork 2k
Dependencies not provided in tests. #1956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi Maxim, what was the actual error you ran into? Can you post it here? |
Dependencies injected to test class by rule.inject(), but not injected in View-class. |
The activity that hosts the view also needs to be annotated with @AndroidEntryPoint
public static final class TestActivity extends AppCompatActivity {}
...
controller = Robolectric.buildActivity(TestActivity.class); |
I checked instrumental tests with Hilt and dependencies successfully injected. But in local tests injection doesn't work. |
Yep, I was able to reproduce your issue. Turns out our bytecode injected classes do not get used when running Robolectric from AndroidStudio (via the play button). Things work when testing via There's a couple work arounds:
@AndroidEntryPoint(AppCompatActivity.class)
public static final class MyActivity extends Hilt_MyActivity {...} Edit: Also see Dany's suggestion below: #1956 (comment) Thanks for reporting this! I've made a note of this in the testing documentation. |
Thanks for supporting! |
I wanted to add, that this is a known issue we are working with the Android Gradle Plugin team to fix, specifically b/37076369. The bytecode transform is done but when running tests from Android Studio the IDE does not grab the transformed classes, which causes injection not to occur in Alternatively you can configure Android Studio to execute tests via the Gradle test task instead of its internal task.
We'll update the docs to mention the workarounds while a fix is being worked on. |
#1956 Link: [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=319808706
#1956 Link: [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=319808706
This bug still remains.... |
- Fix issue with Robolectric & Hilt to apply bytecode changes for local tests (google/dagger#1956 (comment))
Uh oh!
There was an error while loading. Please reload this page.
Hi! I tried to use Hilt, and had a problem during testing
APPLICATION and COUNTRIES-FEATURE modules contain in INJECTOR Gradle-module.
The text was updated successfully, but these errors were encountered: