Hi I have the something similar in my production code. A simple method that will throw an exception:
class Production {
fun doWork(): String {
throw IllegalArgumentException()
}
}
However, when I mock this Production
class with Mockk, it runs the underlying doWork()
method instead of mocking the method call:
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
class Test {
@MockK
lateinit var production: Production
@Before
fun setup() {
MockKAnnotations.init(this)
}
@Test
fun test() {
every { production.doWork() } returns "Str"
assertEquals("Str", production.doWork())
}
}
The test fails with java.lang.IllegalArgumentException
. Shouldn't Mockk be mocking this method call in Production
class? I have a feeling that this could be a misunderstanding on my part coming from a Mockito background.