-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Avoiding duplication in instrumentation tests with Hilt #1896
Comments
Hi Luis, thanks for the feed back!
Yep, totally agree. We have plans to improve this part of the API, although how exactly we'll address it hasn't been decided yet (i.e. whether it will be through base test class or some other mechanism). Hopefully we can find some balance between easily setting up bindings across multiple tests but also allowing each test to be flexible enough to configure itself differently from other tests.
Most of this should work, e.g. public abstract class BaseTest {
@Rule public final HiltAndroidRule rule = new HiltAndroidRule(this);
@Inject Foo foo;
@Before
public final void baseSetup() {
rule.inject();
}
} Note that the test must still be annotated with @HiltAndroidTest
public class MyTest extends BaseTest {
...
} |
Thanks for the prompt reply!
For what it's worth, I think this added flexibility is great.
Agreed. This is much less of an inconvenience. Thanks for the heads up on the viability of |
My previous testing setup used separate component configurations to swap out production bindings for testing ones. Since the swapping of bindings was happening in
TestApplicationComponent
I never had to worry about doing this on each individual test. This was nice.Currently, all of my UI tests extend
BaseTest
which runs rules common to all UI tests (I've also moved someApplicationComponent
bindings that used to be injected into myTestApp
toBaseTest
since the new recommendation is to not use@CustomTestApplication
).BaseTest
seemed like a natural place to put@UninstallModules
and@HiltAndroidTest
.However, doing so leads to an
IllegalStateException
becauseMarkThatRulesRanRule
expects the runtime class to be annotated with@HiltAndroidTest
.The suggested approach seems to be adding
@UninstallModules
and@HiltAndroidTest
to each test. I would really like to avoid this for 2 reasons:Is avoiding this duplication possible with Hilt?
The text was updated successfully, but these errors were encountered: