Bug: 288442188

Clone this repo:
  1. 6c72665 Merge Android 14 QPR2 to AOSP main by Xin Li · 8 weeks ago main master
  2. 0a4134e Merge Android 24Q1 Release (ab/11220357) by Xin Li · 4 months ago
  3. 6de029b Allow mockito-kotlin use in host tests by Andriy Kozachuk · 5 months ago
  4. 0d842e3 Merge remote-tracking branch 'goog/mirror-aosp-main' into am: 97b4dba341 by Magdi · 6 months ago
  5. 97b4dba Merge remote-tracking branch 'goog/mirror-aosp-main' into 'udc-mainline-prod' by Magdi · 6 months ago aml_tz5_341510010 android14-mainline-adservices-release android14-mainline-appsearch-release android14-mainline-art-release android14-mainline-cellbroadcast-release android14-mainline-conscrypt-release android14-mainline-extservices-release android14-mainline-networking-release android14-mainline-os-statsd-release android14-mainline-permission-release android14-mainline-resolv-release android14-mainline-sdkext-release android14-mainline-tethering-release android14-mainline-uwb-release android14-mainline-wifi-release aml_adb_340912530 aml_adb_341517070 aml_adb_341520010 aml_ads_341316030 aml_ads_341413000 aml_ads_341517040 aml_ads_341615050 aml_art_341311100 aml_art_341411300 aml_art_341514410 aml_art_341514450 aml_art_341615020 aml_ase_341310010 aml_ase_341410000 aml_ase_341510000 aml_cbr_341311010 aml_cbr_341410010 aml_cbr_341510010 aml_cbr_341610000 aml_cfg_341510000 aml_con_341310090 aml_con_341410300 aml_con_341511080 aml_con_341614000 aml_ext_341317010 aml_ext_341414010 aml_ext_341518010 aml_ext_341620040 aml_ips_341510000 aml_ips_341611000 aml_net_341310020 aml_net_341311010 aml_net_341411030 aml_net_341510000 aml_net_341510050 aml_net_341610030 aml_neu_341510000 aml_odp_341610000 aml_per_341311000 aml_per_341410020 aml_per_341510010 aml_per_341614000 aml_res_341311030 aml_res_341410010 aml_res_341510000 aml_sch_341510000 aml_sdk_341410000 aml_sdk_341510000 aml_sta_341311010 aml_sta_341410000 aml_sta_341511040 aml_sta_341615000 aml_tet_341310230 aml_tet_341411060 aml_tet_341511010 aml_tet_341610020 aml_tz5_341510010 aml_uwb_341310030 aml_uwb_341310300 aml_uwb_341511050 aml_uwb_341513070 aml_wif_341310010 aml_wif_341410080 aml_wif_341510000 aml_wif_341610000

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:

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.

Building

Mockito-Kotlin is built with Gradle.

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

Versioning

Mockito-Kotlin roughly follows SEMVER; version names are parsed from git tags using git describe.

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.

Testing thus must be done in two stages: one to build the base artifact to test against, and the actual execution of the tests against the built artifact:

  • ./gradlew assemble builds the base artifact
  • ./gradlew test runs the tests against the built artifact.

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, set an environment variable KOTLIN_VERSION and run 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.