How to verify a top level function was called with Mockk?

1.3k views Asked by At

How to verify that a top level (static) function was called in a test with MockK?

Simple approach like:

verify { someTopLevelFunction("some text") }

results in io.mockk.MockKException: can't find stub kotlin.Unit.

1

There are 1 answers

4
Murph_Fish On BEST ANSWER

You would mockk the same way you mockk extension functions https://mockk.io/#extension-functions

In practice generally:

mockkStatic(ClassNameWhereFunctionIsLocated::class)

verify {
    someTopLevelFunction("some text")
}