mockkConstructor

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.

Once used, every constructor of the given class will start returning a singleton that can be mocked. Rather than building a new instance every time the constructor is called, MockK generates a singleton and always returns the same instance. This will apply to all constructors for a given class, there is no way to distinguish between them.

Samples

See also

To manually cancel mock


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.