https://kotlinlang.org logo
#mockk
Title
# mockk
c

Cody Engel

10/08/2019, 10:45 PM
What’s the difference between
clearAllMocks
and
unmockkAll
? I have the following test rule and when I used
clearAllMocks
in the finished function I was seeing some tests failing because a
mockkObject
wasn’t being cleared. With
unmockkAll
though it resolved the issue.
Copy code
class MockKTestRule(private val target: Any) : TestWatcher() {
    override fun starting(description: Description?) {
        super.starting(description)
        MockKAnnotations.init(target)
    }

    override fun finished(description: Description?) {
        unmockkAll() // clearAllMocks doesn't work for all use cases
        super.finished(description)
    }
}
But I don’t understand what the difference is? When would I want to use
clearAllMocks
over
unmockkAll
?
133 Views