Package dagger.hilt.android.testing
Class HiltAndroidRule
- java.lang.Object
-
- dagger.hilt.android.testing.HiltAndroidRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class HiltAndroidRule extends java.lang.Object implements org.junit.rules.TestRule
ATestRule
for Hilt that can be used with JVM or Instrumentation tests.This rule is required. The Dagger component will not be created without this test rule.
-
-
Constructor Summary
Constructors Constructor Description HiltAndroidRule(java.lang.Object testInstance)
Creates a new instance of the rules.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement baseStatement, org.junit.runner.Description description)
HiltAndroidRule
componentReady()
Completes Dagger component creation ifdelayComponentReady()
was used.HiltAndroidRule
delayComponentReady()
Delays creating the component untilcomponentReady()
is called.void
inject()
Completes Dagger injection.
-
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement baseStatement, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
inject
public void inject()
Completes Dagger injection. Must be called before accessing inject types. Must be called after any non-static test module have been added. IfdelayComponentReady()
was used, this must be called aftercomponentReady()
.
-
delayComponentReady
public HiltAndroidRule delayComponentReady()
Delays creating the component untilcomponentReady()
is called. This is only necessary in the case that a dynamically bound value (e.g. configuring an @BindValue field in @Before or @Test method) is requested before test case execution begins.Examples of early binding requests include an Activity launched by a test rule, or an entry points in a
OnComponentReadyRunner
.If this method is called,
componentReady()
must be called before the test case finishes.
-
componentReady
public HiltAndroidRule componentReady()
Completes Dagger component creation ifdelayComponentReady()
was used. Binds the current value ofBindValue
fields. Normally this happens automatically. This method may only be called ifdelayComponentReady()
was used to delay value binding.- Returns:
- an instance of the test rule for chaining
-
-