How do you Mockk a Kotlin top level function?

The following syntax has worked to me.

mockkStatic(::sayHello.javaMethod!!.declaringClass.kotlin)

I’m surprised there is nothing on the jvm-stdlib yet for this.

Edit:
This overload has now been introduced officially:
https://github.com/mockk/mockk/pull/518

mockkStatic(::sayHello)

Leave a Comment