public final class HiltAndroidRule
extends java.lang.Object
implements org.junit.rules.TestRule
TestRule
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 and Description |
---|
HiltAndroidRule(java.lang.Object testInstance)
Creates a new instance of the rules.
|
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement baseStatement,
org.junit.runner.Description description) |
HiltAndroidRule |
componentReady()
Completes Dagger component creation if
delayComponentReady was used. |
HiltAndroidRule |
delayComponentReady()
Delays creating the component until
componentReady() is called. |
void |
inject()
Completes Dagger injection.
|
public HiltAndroidRule(java.lang.Object testInstance)
this
.public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement baseStatement, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
public void inject()
delayComponentReady()
was used, this must
be called after componentReady()
.public HiltAndroidRule delayComponentReady()
componentReady()
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.
public HiltAndroidRule componentReady()
delayComponentReady
was used. Binds the current
value of BindValue
fields. Normally this happens automatically. This method may only be
called if delayComponentReady
was used to delay value binding.