I'm using MockK as mock library for kotlin, for some reason I get an error on the every{} line.
io.mockk.MockKException: Missing calls inside every { ... } block.
this is my test class
internal class TestClass {
private val service: MyService = mockk(relaxed = true)
private val dao: MyDao = mockk(relaxed = true)
private val repository: MyRepository = MyRepositoryImp(
service = service,
dao = dao,
)
@Test
fun test() = runBlocking {
val expected = SOMETHING
every { repository.getValues() } returns flowOf(SOMETHINGELSE) // crash
assertEquals(1, 1)
}
}
MyService is just a retrofit interface
internal interface MyService {
@GET("123")
suspend fun getRemoteData(): Response<SOMECLASS>
}
Anyone has any idea? thanks!
You've instantiated the repository as a real instance. That means that it'll actually execute the code inside its implementation and that's known as the 'subject under test'.
But every { ... } returns ... needs a mockk instance.
So in your example, it should be
every { service.getRemoteData() } returns ...
or
every { dao.someMethod() } returns ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With