Package io.mockk

Types

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

Functions

Link copied to clipboard
fun checkUnnecessaryStub(vararg mocks: Any): <Error class: unknown class>

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): <Error class: unknown class>

Clears all regular, object, static and constructor mocks.

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

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): <Error class: unknown class>

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): <Error class: unknown class>

Cancel static mocks.

Link copied to clipboard
fun <T> coEvery(stubBlock: suspend <Error class: unknown class>.() -> T): <Error class: unknown class><T, T>

Starts a block of stubbing for coroutines. Part of DSL. Similar to every

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

Exclude calls from recording for a suspend block

Link copied to clipboard
fun coJustRun(stubBlock: suspend <Error class: unknown class>.() -> Unit): <Error class: unknown class>

Stub block to return Unit result as a coroutine block. Part of DSL. Similar to justRun

Link copied to clipboard
fun confirmVerified(vararg mocks: Any): <Error class: unknown class>

Checks if all recorded calls were verified.

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

Verifies that calls were made inside a coroutine.

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

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

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

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 <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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

Link copied to clipboard
fun <T> every(stubBlock: <Error class: unknown class>.() -> T): <Error class: unknown class><T, T>

Starts a block of stubbing. Part of DSL.

Link copied to clipboard
fun excludeRecords(current: Boolean = true, excludeBlock: <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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): <Error class: unknown class>

Checks if provided mock is mock of certain type

Link copied to clipboard
fun justRun(stubBlock: <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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,     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): <Error class: unknown class>

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): <Error class: unknown class>

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): <Error class: unknown class>

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

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

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): <Error class: unknown class>

Registers instance factory and returns object able to do deregistration.

Link copied to clipboard
inline fun <T : Any> slot(): <Error class: unknown class>

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(): <Error class: unknown class>

Cancels object, static and constructor mocks.

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

Cancel constructor mocks.

Link copied to clipboard
inline fun unmockkObject(vararg objects: Any): <Error class: unknown class>

Cancel object mocks.

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

Cancel static mocks.

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

Cancel static mocks.

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

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

Link copied to clipboard
fun verifyAll(inverse: Boolean = false, verifyBlock: <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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

Link copied to clipboard
fun verifyOrder(inverse: Boolean = false, verifyBlock: <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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: <Error class: unknown class>.() -> Unit): <Error class: unknown class>

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.

Properties

Link copied to clipboard
val KFunction<*>.declaringKotlinFile: KClass<out Any>

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