Hey
I am experiencing a serious issue - it looks like mocking answer for a parametrised suspended method does not work as expected:
class ExampleUnitTest {
private val repository = mockk<AlbumRepository>()
private val cut = GetAlbumUseCase(repository)
@Test
fun `when execute return success`() {
// given
val albumName = "Thriller"
val artistName = "Michael Jackson"
val mbId = "123"
// when
val actual = runBlocking { cut.execute(albumName, artistName, mbId) }
// then
}
}
no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
io.mockk.MockKException: no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
at app//io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:93)
The answer can't be found (most likely due to
continuation {}
param).
I have crafted a sample project to reproduce this. Steps:
1. Open project using
Android Studio
2. Run
ExampleUnitTest
tests
Can someone take a look? Is there any workaround?