mockkObject
Builds an Object mock. Any mocks of this exact object are cancelled before it's mocked.
This lets you mock object methods with every.
Example:
object CalculatorObject {
fun add(a: Int, b: Int) = a + b
}
mockkObject(CalculatorObject)
every { ObjBeingMocked.add(1, 2) } returns 55Content copied to clipboard
See also
To manually cancel mock
inline fun mockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false, block: () -> Unit)(source)
Builds a static mock and unmocks it after the block has been executed.