I need to verify if bar
function is called or not using MockK library.
MyFile.kt
fun foo() {
bar()
}
private fun bar() { ... }
How can I mock the 'bar' function?
I am trying the following.
@Test
fun test() {
mockkStatic("com.mypkg.MyFileKt")
every { bar() } returns Unit
foo()
verify(exactly = 1) { bar() }
}
This gives compile-time error: Cannot access 'bar': it is private in file
.
It works fine if I make the bar function internal. Probably I will have to spy on it but cannot find an example to do that.