Skip to content
Oleksiy Pylypenko edited this page Mar 8, 2019 · 20 revisions

MockK development wiki

Fresh development setup

  1. git clone git@github.com:mockk/mockk.git
  2. install Android SDK (optional)
  3. Open in IntelliJ IDEA

Main modules

Most of MockK implementation is based on the multi-platform code. Few attempts were made to extend it to JS and Native platforms, but so far only JVM and AIT(Android instrumented test) are supported.

JVM

  • io.mockk:mockk (mockk/jvm)
    JVM MockK implementation
    • io.mockk:mockk-dsl-jvm (dsk/jvm)
      JVM support functions for DSL
    • io.mockk:mockk-common (mockk/common)
      common MockK implementation
      • io.mockk:mockk-dsl (dsl/common)
        common MockK DSL interface
    • io.mockk:mockk-agent-jvm (agennt/jvm)
      call interception for JVM
      • io.mockk:mockk-agent-common (agent/common)
        common call interception code(Android and JVM)
      • io.mockk:mockk-agent-api (agent/common)
        common API(Android and JVM) for call interception
      • org.objenesis:objenesis (2.6)
        library to instantiate objects
      • net.bytebuddy:byte-buddy (1.9.3)
        library to modify byte-code
      • net.bytebuddy:byte-buddy-agent (1.9.3)
        library to modify byte-code on flight

Android instrumented tests

  • io.mockk:mockk-android (mockk/android)
    Android implementation is based on JVM(with JVM agent exclusion)
    • io.mockk:mockk (mockk/jvm)
      JVM MockK implementation
      • io.mockk:mockk-common (mockk/common)
        common MockK implementation
        • io.mockk:mockk-dsl (dsl/common)
          common MockK DSL interface
      • io.mockk:mockk-dsl-jvm (dsl/jvm)
        JVM support functions for DSL
    • io.mockk:mockk-agent-android (agent/android)
      call interception for Android (drop-in replacement for mockk-agent-jvm)
      • io.mockk:mockk-agent-common (agent/common)
        common call interception code(Android and JVM)
      • io.mockk:mockk-agent-api (agent/common)
        common API(Android and JVM) for call interception
      • org.objenesis:objenesis (2.6)
        library to instantiate objects
      • com.linkedin.dexmaker:dexmaker (2.12.1)
        library to modify dex-code

Troubleshooting

Transformation dumping

To see results of class transformation(and untransformation) add following system variable:

java  -Dio.mockk.classdump.path=some-directory ...

After running your code transformed class files should appear in some-directory.

Enabling trace logs

Accessing information in IDEA Debugger

Just use following expression:

(MockKGateway.implementation() as JvmMockKGateway).stubRepo.stubs.map
```. 

This particular gives access to all stubs, but you may access different other objects from `JvmMockKGateway`

## Topics

 * Basics
   * [DSL, Gateway & Agent layers 14:13](https://youtu.be/NZnfpeiBDFA)
   * [Mock creation - basic flow 21:14](https://youtu.be/JD1ox-yH73g)
   * [Mock creation - inlining 29:32](https://youtu.be/9rxw6BEWo-4)
   * Mock creation: subclass instrumentation
   * Mock creation: instantiation
   * Mock creation: cancellation
   * (MockK/SpyK creation)
   * mockkObject, mockkStatic, mockkConstructor
   * Mocking by annotation
   * Tests(prinicples & layout)
 * Code transformation
   * ByteBuddy inlining
   * ByteBuddy subclassing
   * DEX Maker inlining
   * DEX Maker subclassing
 * Call recording
   * Recording states
   * Signatures
   * Autohinting
   * Chain detection
 * Verification 
   * verify
   * verifyAll
   * verifyOrder
   * verifySequence
   * verify(timeout=X)
Clone this wiki locally