MockKExtension

class MockKExtension : TestInstancePostProcessor, ParameterResolver, AfterEachCallback, AfterAllCallback

MockK JUnit5 extension.

Parameters can use MockK and RelaxedMockK. Class properties can use MockK, RelaxedMockK and SpyK.

unmockkAll will be called after each test function execution if the test lifecycle is set to TestInstance.Lifecycle.PER_METHOD (JUnit 5 default), or after all test functions in the test class have been executed if the test lifecycle is set to TestInstance.Lifecycle.PER_CLASS. unmockkAll will not be called if the KeepMocks annotation is present or if the mockk.junit.extension.keepmocks Gradle property is set to true.

Usage: declare @ExtendWith(MockKExtension::class) on a test class.

Alternatively –Djunit.extensions.autodetection.enabled=true may be placed on a command line.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
annotation class CheckUnnecessaryStub
Link copied to clipboard
object Companion
Link copied to clipboard
annotation class ConfirmVerification
Link copied to clipboard

Prevent calling unmockkAll after each test execution

Link copied to clipboard
annotation class RequireParallelTesting

Require parallel testing by disabling the clearAllMocks call after each test execution; it is not thread-safe.

Functions

Link copied to clipboard
open override fun afterAll(context: ExtensionContext)
Link copied to clipboard
open override fun afterEach(context: ExtensionContext)
Link copied to clipboard
open override fun postProcessTestInstance(testInstance: Any, context: ExtensionContext)
Link copied to clipboard
open override fun resolveParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Any?
Link copied to clipboard
open override fun supportsParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Boolean