Mokkery API Reference

website·Indexed 32 days ago

https://mokkery.dev

API documentation for Mokkery, including its Gradle plugin (mokkery-gradle), core tooling (mokkery-core-tooling), coroutines support (mokkery-coroutines), and runtime components (mokkery-runtime).

Tokens
99.2K
Snippets
811
Records
1K
Agent score
64%

What's inside Mokkery

  1. Define sequential answers for non-suspend functions using BlockingSequentialAnswerBuilder

    The BlockingSequentialAnswerBuilder<T> is a marker interface used to define a sequence of answers for non-suspend function calls. It allows developers to specify a series of different return values or behaviors that will be triggered one after another on subsequent calls to the mocked function.
  2. Use TypeRegistryAutofillProvider to register type-specific value providers

    The TypeRegistryAutofillProvider interface allows you to register value providers for specific types. Note that this provider does not support polymorphism: registering a provider for an interface A will only provide values for A::class. If a value is needed for a specific implementation like AImpl, that implementation must be registered separately.
  3. Use the Autofill answer for default mock returns

    The Autofill object (inheriting from Answer.Unified<Any>) is used by the Mokkery runtime whenever a call is made to a mock that is configured in dev.mokkery.MockMode.autofill but has no specifically defined answer. It automatically provides a return value based on the mock's configuration. For detailed information on how these values are determined, refer to AutofillProvider.forMockMode.
  4. Use the Function interface to represent Kotlin functions

    The dev.mokkery.context.Function interface represents a Kotlin function within the Mokkery runtime. It provides metadata about the function, including its unique identifier, name, parameters, and return type.
    interface Function {
        val id: Function.Id
        val name: String
        val parameters: List<Function.Parameter>
        val returnType: KClass<*>
    }
  5. Access call metadata and context in MokkeryBlockingCallScope

    Within a MokkeryBlockingCallScope, you can use the following properties to retrieve information about the current execution context:

    • call: Returns the current FunctionCall object.
    • self: Returns the instance of the object being called (equivalent to this in the scope of the currently called function).
    • supers: Returns a map of available super calls for the currently called function, keyed by KClass.
    • callHooks: Returns the MokkeryCallHooks associated with the current scope.
    • mokkeryContext: Provides access to the underlying MokkeryContext.