Package-level declarations

Types

Link copied to clipboard
expect object MockK
actual object MockK
Link copied to clipboard

Properties

Link copied to clipboard

Returns the defining top-level extension function's Class.

Functions

Link copied to clipboard
fun checkUnnecessaryStub(vararg mocks: Any)

Checks if all recorded calls are necessary.

Link copied to clipboard
inline fun clearAllMocks(answers: Boolean = true, recordedCalls: Boolean = true, childMocks: Boolean = true, regularMocks: Boolean = true, objectMocks: Boolean = true, staticMocks: Boolean = true, constructorMocks: Boolean = true, currentThreadOnly: Boolean = false)

Clears all regular, object, static and constructor mocks.

Link copied to clipboard

Removes all objects stored within the internal stubs collection.

Link copied to clipboard
inline fun clearConstructorMockk(vararg classes: KClass<*>, answers: Boolean = true, recordedCalls: Boolean = true, childMocks: Boolean = true)

Clears constructor mock.

Link copied to clipboard
fun clearMocks(firstMock: Any, vararg mocks: Any, answers: Boolean = true, recordedCalls: Boolean = true, childMocks: Boolean = true, verificationMarks: Boolean = true, exclusionRules: Boolean = true)

Resets information associated with specified mocks. To clear all mocks use clearAllMocks.

Link copied to clipboard
inline fun clearStaticMockk(vararg classes: KClass<*>, answers: Boolean = true, recordedCalls: Boolean = true, childMocks: Boolean = true)

Clears static mocks.

fun clearStaticMockk(vararg functions: KFunction<*>)
fun clearStaticMockk(vararg functions: KProperty<*>)

Clear static mocks.

Link copied to clipboard
fun <T> coEvery(stubBlock: suspend MockKMatcherScope.() -> T): MockKStubScope<T, T>

Starts a block of stubbing for coroutines. Part of DSL. Similar to every, but works with suspend functions.

Link copied to clipboard
fun coExcludeRecords(current: Boolean = true, excludeBlock: suspend MockKMatcherScope.() -> Unit)

Exclude calls from recording for a suspend block

Link copied to clipboard

Stub block to never return. Part of DSL.

Link copied to clipboard

Stub block to return Unit result as a coroutine block. Part of DSL. Similar to justRun, but works with suspend functions.

Link copied to clipboard
fun confirmVerified(vararg mocks: Any, clear: Boolean = false)

Checks if all recorded calls were verified.

Link copied to clipboard
fun coVerify(ordering: Ordering = Ordering.UNORDERED, inverse: Boolean = false, atLeast: Int = 1, atMost: Int = Int.MAX_VALUE, exactly: Int = -1, timeout: Long = 0, verifyBlock: suspend MockKVerificationScope.() -> Unit)

Verifies that calls were made inside a coroutine.

Link copied to clipboard
fun coVerifyAll(inverse: Boolean = false, verifyBlock: suspend MockKVerificationScope.() -> Unit)

Verifies that all calls inside verifyBlock happened. Does not verify any order. Coroutine version

Link copied to clipboard

Verifies that calls and their count. Coroutine version

Link copied to clipboard
fun coVerifyOrder(inverse: Boolean = false, verifyBlock: suspend MockKVerificationScope.() -> Unit)

Verifies that all calls inside verifyBlock happened, checking that they happened in the order declared. Coroutine version.

Link copied to clipboard
fun coVerifySequence(inverse: Boolean = false, verifyBlock: suspend MockKVerificationScope.() -> Unit)

Verifies that all calls inside verifyBlock happened, and no other call was made to those mocks. Coroutine version.

Link copied to clipboard
fun <T> every(stubBlock: MockKMatcherScope.() -> T): MockKStubScope<T, T>

Starts a block of stubbing. Part of DSL.

Link copied to clipboard
fun excludeRecords(current: Boolean = true, excludeBlock: MockKMatcherScope.() -> Unit)

Exclude calls from recording

Link copied to clipboard
fun isMockKMock(mock: Any, regular: Boolean = true, spy: Boolean = false, objectMock: Boolean = false, staticMock: Boolean = false, constructorMock: Boolean = false): Boolean

Checks if provided mock is mock of certain type

Link copied to clipboard

Stub block to return Unit result. Part of DSL.

Link copied to clipboard
inline fun <T : Any> mockk(name: String? = null, relaxed: Boolean = false, vararg moreInterfaces: KClass<*>, relaxUnitFun: Boolean = false, mockValidator: MockkValidator = MockkValidator(RestrictMockkConfiguration()), block: T.() -> Unit = {}): T

Builds a new mock for specified class.

Link copied to clipboard
inline fun <T : Any> mockkClass(type: KClass<T>, name: String? = null, relaxed: Boolean = false, vararg moreInterfaces: KClass<*>, relaxUnitFun: Boolean = false, block: T.() -> Unit = {}): T

Builds a mock for an arbitrary class

Link copied to clipboard
inline fun mockkConstructor(vararg classes: KClass<*>, recordPrivateCalls: Boolean = false, localToThread: Boolean = false)

Builds a constructor mock. Old constructor mocks of same classes are cancelled before.

inline fun mockkConstructor(vararg classes: KClass<*>, recordPrivateCalls: Boolean = false, localToThread: Boolean = false, block: () -> Unit)

Builds a constructor mock and unmocks it after the block has been executed.

Link copied to clipboard
inline fun mockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false)

Builds an Object mock. Any mocks of this exact object are cancelled before it's mocked.

inline fun mockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false, block: () -> Unit)

Builds a static mock and unmocks it after the block has been executed.

Link copied to clipboard
inline fun mockkStatic(vararg classes: String)

Builds a static mock. Old static mocks of same classes are cancelled before.

inline fun mockkStatic(vararg classes: KClass<*>)

Builds a static mock. Any mocks of this exact class are cancelled before it's mocked

inline fun mockkStatic(vararg classes: String, block: () -> Unit)
inline fun mockkStatic(vararg classes: KClass<*>, block: () -> Unit)

Builds a static mock and unmocks it after the block has been executed.

fun mockkStatic(vararg functions: KFunction<*>)
fun mockkStatic(vararg functions: KProperty<*>)

Builds a static mock. Any mocks of this function's declaring class are cancelled before it's mocked

inline fun mockkStatic(vararg functions: KFunction<*>, block: () -> Unit)
inline fun mockkStatic(vararg functions: KProperty<*>, block: () -> Unit)

Builds a static mock and unmocks it after the block has been executed.

Link copied to clipboard
inline fun <T : Any> registerInstanceFactory(noinline instanceFactory: () -> T): Deregisterable

Registers instance factory and returns object able to do deregistration.

Link copied to clipboard
inline fun <T> slot(): CapturingSlot<T>

Creates new capturing slot.

Link copied to clipboard
inline fun <T : Any> spyk(name: String? = null, vararg moreInterfaces: KClass<*>, recordPrivateCalls: Boolean = false, block: T.() -> Unit = {}): T

Builds a new spy for specified class. Initializes object via default constructor.

inline fun <T : Any> spyk(objToCopy: T, name: String? = null, vararg moreInterfaces: KClass<*>, recordPrivateCalls: Boolean = false, block: T.() -> Unit = {}): T

Builds a new spy for specified class, copying fields from objToCopy.

Link copied to clipboard
inline fun unmockkAll()

Cancels object, static and constructor mocks.

Link copied to clipboard
inline fun unmockkConstructor(vararg classes: KClass<*>)

Cancel constructor mocks.

Link copied to clipboard
inline fun unmockkObject(vararg objects: Any)

Cancel object mocks.

Link copied to clipboard
inline fun unmockkStatic(vararg classes: String)
inline fun unmockkStatic(vararg classes: KClass<*>)

Cancel static mocks.

fun unmockkStatic(vararg functions: KFunction<*>)
fun unmockkStatic(vararg functions: KProperty<*>)

Cancel static mocks.

Link copied to clipboard
fun verify(ordering: Ordering = Ordering.UNORDERED, inverse: Boolean = false, atLeast: Int = 1, atMost: Int = Int.MAX_VALUE, exactly: Int = -1, timeout: Long = 0, verifyBlock: MockKVerificationScope.() -> Unit)

Verifies that calls were made in the past. Part of DSL.

Link copied to clipboard
fun verifyAll(inverse: Boolean = false, verifyBlock: MockKVerificationScope.() -> Unit)

Verifies all the calls of the mocks specified inside verifyBlock. Once a mock is specified inside verifyBlock, all its recorded calls are expected to be verified within verifyBlock. Otherwise, the verification fails. Does not verify any order.

Link copied to clipboard

Verifies that calls and their count

Link copied to clipboard
fun verifyOrder(inverse: Boolean = false, verifyBlock: MockKVerificationScope.() -> Unit)

Verifies that all calls inside verifyBlock happened, checking that they happened in the order declared.

Link copied to clipboard
fun verifySequence(inverse: Boolean = false, verifyBlock: MockKVerificationScope.() -> Unit)

Verifies that all calls inside verifyBlock happened, and no other call was made to those mocks

Link copied to clipboard
inline fun <T : Any, R> withInstanceFactory(noinline instanceFactory: () -> T, block: () -> R): R

Executes block of code with registering and unregistering instance factory.