I set up my instrumentation tests to use the appropriate test app dependencies using dagger.
My TestApplicationComponent
@Component(modules = [
(AndroidInjectionModule::class),
(TestApplicationModule::class),
(ActivityBuilderTest::class),
(FragmentBuilderTest::class),
(AndroidSupportInjectionModule::class)])
@Singleton
interface TestApplicationComponent: AndroidInjector<TestApplication> {
@Component.Factory
abstract class Builder: AndroidInjector.Factory<TestApplication>
}
My TestApplication class
class TestApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerTestApplicationComponent.factory().create(this)
}
}
In my test instrumentation setup (@Before), I need to call a RepositoryImplementation, also used in the app, to save an object to the database for some specific test cases. For example, save an "ongoing status", to make sure when a user opens the app it redirects to the correct screen.
The objective would be for something like this to work:
Test Class:
class ActivityTest {
@Inject
lateinit var appointmentRepository: AppointmentRepository
@Before
fun setUp() {
appointmentRepository.saveAppointmentStatus()
}
**TESTING**
}
How can I achieve this? Currently and obviously appointmentRepository remains null.