Closed NurseyitTursunkulov closed 4 years ago
Create a BaseTest that extends KoinTest. Inside it, you create another instance of startKoin with modules(FakeRepository())
@NurseyitTursunkulov I'm working on the same project. Could you share your progress?
@HarryMMR They are complaining that it is not the right repository (org.koin.core.error.NoBeanDefFoundException: No definition found for 'ActualRepository'
I tried this :
@Test fun
should inject my components`() {
startKoin {
modules(
module {
single { FakeRepository() }
single { Application() }
single { MainViewModel(get(), get()) }
})
}
// directly request an instance
val fakeRepository = declareMock<FakeRepository>(){
val task1 = Task("Title1", "Description1")
val task2 = Task("Title2", "Description2", true)
val task3 = Task("Title3", "Description3", true)
tasksRepository.addTasks(task1, task2, task3)
}
assertNotNull(fakeRepository)
assertEquals(fakeRepository, mainViewModel.repo)
}`
Sorry for this weird code, the quotes do not work as expected
Could you please show an example in a GitHub?
I want to inject Koin in this project https://github.com/android/architecture-samples/tree/usecasesrename/app/src/main/java/com/example/android/architecture/blueprints/todoapp. They have a RealRepository for prod and FakeRepository for testing purposes. I can easily change modules in Application ` class MainApplication : Application() {
} ` but it is manual work and means that every time I want to run tests I have to substitute it here. Is there a way such depending on the use cases Koin would give me the right modules?