I'm trying to run android instrumentation tests for the fragments that share the same ViewModel. The ViewModel have some arguments. I use koin, but when using activityViewModels in the tests koin does not inject the ViewModel.
class SomeFragment() : Fragment() {
private val viewModel: SomeViewModel by activityViewModels()
... more code
}
class SomeFragmentTest() : KoinTest{
@Before
fun setup() {
val viewModel: SomeViewModel = mockk(relaxed = true)
startKoin { loadKoinModules(listOf(
module(override = true) { viewModel },
module(override = true) { factory { appAnalytics } })) }
}
.... more code
}
The message received is
Caused by: java.lang.InstantiationException: java.lang.Class<SomeViewModel> has no zero argument constructor