mockito/mockito-kotlin

Using Mockito with Kotlin

Kotlin

3,160

464 commits

updated Oct 13, 2026

See the code

README

Mockito-Kotlin

Maven Central Version

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

Install

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

build.gradle:

testImplementation "org.mockito.kotlin:mockito-kotlin:x.x.x"

build.gradle.kts:

testImplementation("org.mockito.kotlin:mockito-kotlin: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.

Android Support

See the Android Support wiki.

Building

Mockito-Kotlin is built with Gradle.

  • ./gradlew build builds and tests the project
  • ./gradlew publishToMavenLocal installs the maven artifacts in your local repository
  • ./gradlew check runs the test suite (See Testing below)

Versioning

Mockito-Kotlin roughly follows SEMVER

Testing

Mockito-Kotlin's test suite is located in a separate tests module, to allow running the tests using several Kotlin versions whilst still keeping the base module at a recent version.

  • ./gradlew check runs the checks including tests.

Usually it is enough to test only using the default Kotlin versions; CI will test against multiple versions. If you want to test using a different Kotlin version locally, add the -PtestKotlinVersion=1.2.3 argument to the Gradle invocation while running the tests.

Acknowledgements

mockito-kotlin was created and developed by nhaarman@ after which the repository was integrated into the official Mockito GitHub organization. We would like to thank Niek for the original idea and extensive work plus support that went into mockito-kotlin.

kotlin
mockito
mockito-kotlin

mockito/mockito-kotlin

Using Mockito with Kotlin

Kotlin

3,160

464 commits

updated Oct 13, 2026

See the code

README

Mockito-Kotlin

Maven Central Version

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

Install

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

build.gradle:

testImplementation "org.mockito.kotlin:mockito-kotlin:x.x.x"

build.gradle.kts:

testImplementation("org.mockito.kotlin:mockito-kotlin: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.

Android Support

See the Android Support wiki.

Building

Mockito-Kotlin is built with Gradle.

  • ./gradlew build builds and tests the project
  • ./gradlew publishToMavenLocal installs the maven artifacts in your local repository
  • ./gradlew check runs the test suite (See Testing below)

Versioning

Mockito-Kotlin roughly follows SEMVER

Testing

Mockito-Kotlin's test suite is located in a separate tests module, to allow running the tests using several Kotlin versions whilst still keeping the base module at a recent version.

  • ./gradlew check runs the checks including tests.

Usually it is enough to test only using the default Kotlin versions; CI will test against multiple versions. If you want to test using a different Kotlin version locally, add the -PtestKotlinVersion=1.2.3 argument to the Gradle invocation while running the tests.

Acknowledgements

mockito-kotlin was created and developed by nhaarman@ after which the repository was integrated into the official Mockito GitHub organization. We would like to thank Niek for the original idea and extensive work plus support that went into mockito-kotlin.

kotlin
mockito
mockito-kotlin

Project health

Overall

4.5/10

Maintained

0/10

Code review

10/10
OpenSSF Scorecard

Significant stargazers

(top 24 of 29)

Omer Katz

378 followers · starred Jun 2023

Jaewoong Eum

13,001 followers · starred Apr 2018

Hong Xu

306 followers · starred Jul 2025

Benoît Quenaudon

340 followers · starred Dec 2017