mock

inline fun <T : Any> mock(extraInterfaces: Array<out KClass<out Any>>? = null, name: String? = null, spiedInstance: Any? = null, defaultAnswer: Answer<Any>? = null, serializable: Boolean = false, serializableMode: SerializableMode? = null, verboseLogging: Boolean = false, invocationListeners: Array<InvocationListener>? = null, stubOnly: Boolean = false, @Incubating useConstructor: UseConstructor? = null, @Incubating outerInstance: Any? = null, @Incubating lenient: Boolean = false): T

Creates a mock for T.

Parameters

extraInterfaces

Specifies extra interfaces the mock should implement.

name

Specifies mock name. Naming mocks can be helpful for debugging - the name is used in all verification errors.

spiedInstance

Specifies the instance to spy on. Makes sense only for spies/partial mocks.

defaultAnswer

Specifies default answers to interactions.

serializable

Configures the mock to be serializable.

serializableMode

Configures the mock to be serializable with a specific serializable mode.

verboseLogging

Enables real-time logging of method invocations on this mock.

invocationListeners

Registers a listener for method invocations on this mock. The listener is notified every time a method on this mock is called.

stubOnly

A stub-only mock does not record method invocations, thus saving memory but disallowing verification of invocations.

useConstructor

Mockito attempts to use constructor when creating instance of the mock.

outerInstance

Makes it possible to mock non-static inner classes in conjunction with useConstructor.

lenient

Lenient mocks bypass "strict stubbing" validation.


inline fun <T : Any> mock(extraInterfaces: Array<out KClass<out Any>>? = null, name: String? = null, spiedInstance: Any? = null, defaultAnswer: Answer<Any>? = null, serializable: Boolean = false, serializableMode: SerializableMode? = null, verboseLogging: Boolean = false, invocationListeners: Array<InvocationListener>? = null, stubOnly: Boolean = false, @Incubating useConstructor: UseConstructor? = null, @Incubating outerInstance: Any? = null, @Incubating lenient: Boolean = false, stubbing: KStubbing<T>.(T) -> Unit): T

Creates a mock for T, allowing for immediate stubbing.

Parameters

extraInterfaces

Specifies extra interfaces the mock should implement.

name

Specifies mock name. Naming mocks can be helpful for debugging - the name is used in all verification errors.

spiedInstance

Specifies the instance to spy on. Makes sense only for spies/partial mocks.

defaultAnswer

Specifies default answers to interactions.

serializable

Configures the mock to be serializable.

serializableMode

Configures the mock to be serializable with a specific serializable mode.

verboseLogging

Enables real-time logging of method invocations on this mock.

invocationListeners

Registers a listener for method invocations on this mock. The listener is notified every time a method on this mock is called.

stubOnly

A stub-only mock does not record method invocations, thus saving memory but disallowing verification of invocations.

useConstructor

Mockito attempts to use constructor when creating instance of the mock.

outerInstance

Makes it possible to mock non-static inner classes in conjunction with useConstructor.

lenient

Lenient mocks bypass "strict stubbing" validation.


inline fun <T : Any> mock(a: Answer<Any>): T

Deprecated (with error)

Use mock() with optional arguments instead.

Replace with

mock<T>(defaultAnswer = a)

inline fun <T : Any> mock(s: String): T

Deprecated (with error)

Use mock() with optional arguments instead.

Replace with

mock<T>(name = s)

inline fun <T : Any> mock(s: MockSettings): T

Deprecated (with error)

Use mock() with optional arguments instead.