question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hilt: Supporting module uninstallation across all tests

See original GitHub issue

From https://developer.android.com/training/dependency-injection/hilt-testing:

This only replaces the binding for a single test class. If you want to replace the binding for all test classes, put the test binding in the test module for Robolectric tests, or in the androidTest module for instrumented tests.

This is in reference to providing modules within a test class vs at the top level. Moving it at the top level works, but it seems like every test is still required to annotate production modules to be uninstalled. The annotation is ignored if we try to use it in an abstract super class for all tests.

What is the approach here? Should we try to also add a hilt rule in the super class? Is there a workaround to avoid uninstalling the same module across all tests?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:15
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Chang-Ericcommented, Jan 14, 2021

Closing this as the above commit should fix this issue.

0reactions
krgauthicommented, Dec 7, 2020

@bcorso This could be a lengthy explanation, I might need to make an example.

Can you describe where your test vs test application live? Are you talking about a case where the test application is in a separate Gradle module from the test?

I’ve got two Gradle modules one for each app, I’ve got a third gradle module with a shared feature from both apps that’s a dependency for each app. I’ve currently got my Espresso tests in that feature gradle module. With Dagger I had two AppComponents for each app (4 total), one for normal builds the other for integration tests. The difference between the components was just one dagger module one had real implementations the other had stubbed implementations for the integration tests.

My issue with adding @UninstallModules to the test in the feature gradle module is that I’d be referring to a dagger module in one / both of the app gradle modules - which I don’t want the feature to have a dependency on. In a multi-module app a lot of the implementation decisions happen at that application layer, dagger could accommodate and I don’t think Hilt is currently - I’m still investigating though.

I think that this is a similar issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

UninstallModules - Dagger
An annotation used to uninstall modules that have previously been installed with InstallIn . This feature should only be used in tests.
Read more >
Hilt testing guide | Android Developers
To replace a binding in a single test instead of all tests, uninstall a Hilt module from a test using the @UninstallModules annotation...
Read more >
Hilt Migration Guide. Dagger is an advanced dependency…
In order to remove the AppComponent in this sample app, all modules ... Let's start migrating tests to Hilt with adding Hilt dependencies...
Read more >
Our Guide To Using Hilt in Android [Senior Developer Review!]
By the way, replacement modules for specific tests have drawbacks: · There will be a compilation error if developers try to uninstall a...
Read more >
Hilt makes testing easier on Android - YouTube
The best android courses in the world: https://codingwithmitch.com/Watch the HILT course here (FREE): ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found