@Replaces on fields
Is your feature request related to a problem? Please describe.
I'm not sure if this is possible, but it'd be nice to be able to use @Replaces on fields as well
Describe the solution you'd like Currently I'd write
@UninstallModules(AutoBindExampleImplSingletonModule::class)
@HiltAndroidTest
class ExampleTest {
@JvmField
@BindValue
val example = mockk<Example>()
}
to inject a mock in a single test. It'd be nice to write
@HiltAndroidTest
class ExampleTest {
@JvmField
@Replaces(ExampleImpl::class)
val example = mockk<Example>()
}
instead.
This is an interesting idea, I did not know about @BindValue. I don't think it's possible to do exactly what you suggest because you'd still need to have @BindValue on the property. But it might be possible to make something that is better.
It's also possible that the test is an input to the graph, in which case this would be possible.
I got some time to look into this but I don't think this is possible unfortunately. The generated code cannot use @UninstallModules because that can only be added to the test class and @TestInstallIn is global in the module. There is also no way to scope the module to the test class as it needs to be nested for that to work. I'll keep this open to think about it some more