Mockito-Kotlin

Download

A small library that provides helper functions to work with Mockito in Kotlin.

Install

Mockito-Kotlin is available on Maven Central and JCenter. For Gradle users, add the following to your build.gradle, replacing x.x.x with the latest version:

testCompile "com.nhaarman:mockito-kotlin:x.x.x"

If you use Kotlin 1.1, you can instead depend on the mockito-kotlin-kt1.1 artifact.

testCompile "com.nhaarman:mockito-kotlin-kt1.1:x.x.x"

Example

A test using Mockito-Kotlin typically looks like the following:

@Test
fun doAction_doesSomething(){ 
  /* Given */
  val mock = mock<MyClass> {
    on { getText() } doReturn "text"
  }
  val classUnderTest = ClassUnderTest(mock)
  
  /* When */
  classUnderTest.doAction()
  
  /* Then */
  verify(mock).doSomething(any())
}

For more info and samples, see the Wiki.

compile "com.nhaarman:mockito-kotlin:1.5.0"

Related Libraries

expekt

BDD assertion library for Kotlin

Last updated 3 mins ago

assertk

assertions for kotlin inspired by assertj

Last updated 3 mins ago

hamkrest

Hamcrest for Kotlin

Last updated 3 mins ago

mockito-kotlin

Using Mockito with Kotlin

Last updated 3 mins ago

kluent

Fluent Assertion-Library for Kotlin

Last updated 3 mins ago