mockk kotlin

Gitter Build Status Release Version Change log Back log codecov Documentation

Support

MockK supports:

Implementation

Implementation is based on dexmaker project. With Anroid P instrumentation tests may use full power of inline instrumentation, so object mocks, static mocks and mocking of final classes are supported. Before Android P only subclassing can be employed and that means you need ‘all-open’ plugin.

Unfortunatelly public CIs alike Travis and Circle are not supporting emulation of Android P because of absense of ARM Anroid P images. Hope this will change soon

Supported features

Feature Unit tests Instrumetation test
< Android P ≥ Android P
annotations
mocking final classes
pure Kotlin mocking DSL
matchers partial specification
chained calls
matcher expressions
mocking coroutines
capturing lambdas
object mocks
private function mocking
property backing field access
extension function mocking (static mocks)

Installation

All you need to get started is just to add a dependency to MockK library.

Unit tests

testImplementation "io.mockk:mockk:{version}"

Android instrumentation tests

androidTestImplementation "io.mockk:mockk-android:{version}"

current version

Documentation

Check full documentation here