What's the difference between mokk() and mokkClass()?

Viewed 970

When I started learning Mockk for testing, I had the following question.

Mockk official sample shows like:

val car = mockk<Car>()

and

val car = mockkClass(Car::class)

I seem the two as the same. What's the difference?

1 Answers

The difference is that the first mock instantiation method takes a type argument, and the second takes a class reference KClass.

So in practice, those examples produce the same result, but I guess the second one has a higher degree of freedom to decouple the class being mocked during runtime.

Related