I am trying to perform a chain call within my unit test using the mockk library within Kotlin. Below is my code:
@MockK
lateinit var crypto: Crypto
@Before
fun setUp() {
MockKAnnotations.init(this, relaxUnitFun = true)
}
@Test
fun testCryptoFunc() {
// Given
// When
every { crypto.sayHello() } returns "gg" // This works
every { crypto.sayHelloTwice("w").sayHello() } returns "gg" //sayHello() is unresolved
// Then
//val c = crypto.sayHelloTwice("ss")
//print("rr")
}
And my implementation code:
fun sayHello(): String {
return "hello"
}
fun sayHelloTwice(a: String): String {
return sayHello() + a
}
I am trying to stub the inner call (sayHello()) but I am getting unresolved reference error. According to the Mockk documentation for chain calls, it says this should be valid.
I've tried cleaning and rebuilding (but running into the compilation error). Tried restarting the IDE. Tried invalidating caches and restarting.
Is there anything that I'm missing/doing wrong?
References: