mockkConstructor
inline fun mockkConstructor(vararg classes: KClass<*>, recordPrivateCalls: Boolean = false, localToThread: Boolean = false)(source)
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.
See also
To manually cancel mock Example:
class ClassToTest {
private val log = Logger()
}
mockkConstructor(Logger::class)
// ClassToTest.log will now use a mock instanceContent copied to clipboard
inline fun mockkConstructor(vararg classes: KClass<*>, recordPrivateCalls: Boolean = false, localToThread: Boolean = false, block: () -> Unit)(source)
Builds a constructor mock and unmocks it after the block has been executed.