How to mock internal interface that is provided by Koin?

32 views Asked by At

Currently trying to write a unit test for my view model in the Android app. The problem is in one of my functions there is a call of the KoinComponent function. This component contents val that is set by koin, looks something like this:

object Component: KoinComponent {
private val api = get<ApiInterface>()
fun doSomething() {}
}

In my viewModel i have a fun that executes doSomething(). Due to it requiring Koin to start test fails. I know that I can mock this but the problem is that KoinComponent is public and ApiInterface is not. If I make the interface public - the mock works fine, otherwise I can't do anything. So the question is: is there any way to make this interface visible for tests or maybe make KoinComponent mock it by itself? Thanks!

Tried to make interface public to mock everything function needs.

0

There are 0 answers