12

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)
Parameswar
  • 1,951
  • 9
  • 34
  • 57

1 Answers1

18

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.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Hardik Bambhania
  • 1,732
  • 15
  • 25