Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mockk exception - no answer found for

Tags:

kotlin

mockk

using mockk for testing kotlin function.

private val serviceObject = mockk<Service>()
private val serviceToBeTested = ServiceToBeTestd(Service)
        
fun test(){
    when(serviceObject.function1(argument1,argument1))
        .thenReturn(<something>)
}

When i try to run it, i get this error:

io.mockk.MockKException: no answer found for: Service(#1).function1(argument1, argument2)

Any idea why ?

ServiceToBeTestd is the service to be tested, Service is wired in it:

open class ServiceToBeTestd
    constructor(private val service: Service)
like image 294
Parameswar Avatar asked Jul 23 '19 12:07

Parameswar


1 Answers

You are using mockito syntax.

Below is correct syntax for mockk.

val car = mockk<Car>()

every { car.drive(Direction.NORTH) } returns Outcome.OK

Please update your syntax.

like image 177
Hardik Bambhania Avatar answered Nov 10 '22 00:11

Hardik Bambhania