README.md
1# Mockito-Kotlin
2[ ![Download](https://maven-badges.herokuapp.com/maven-central/org.mockito.kotlin/mockito-kotlin/badge.svg) ](https://maven-badges.herokuapp.com/maven-central/org.mockito.kotlin/mockito-kotlin)
3
4A small library that provides helper functions to work with [Mockito](https://github.com/mockito/mockito) in Kotlin.
5
6## Install
7
8Mockito-Kotlin is available on Maven Central and JCenter.
9For Gradle users, add the following to your `build.gradle`, replacing `x.x.x` with the latest version:
10
11```groovy
12testImplementation "org.mockito.kotlin:mockito-kotlin:x.x.x"
13```
14
15## Example
16
17A test using Mockito-Kotlin typically looks like the following:
18
19```kotlin
20@Test
21fun doAction_doesSomething(){
22 /* Given */
23 val mock = mock<MyClass> {
24 on { getText() } doReturn "text"
25 }
26 val classUnderTest = ClassUnderTest(mock)
27
28 /* When */
29 classUnderTest.doAction()
30
31 /* Then */
32 verify(mock).doSomething(any())
33}
34```
35
36For more info and samples, see the [Wiki](https://github.com/mockito/mockito-kotlin/wiki).
37
38## Building
39
40Mockito-Kotlin is built with Gradle.
41
42 - `./gradlew build` builds the project
43 - `./gradlew publishToMavenLocal` installs the maven artifacts in your local repository
44 - `./gradlew assemble && ./gradlew test` runs the test suite (See Testing below)
45
46### Versioning
47
48Mockito-Kotlin roughly follows SEMVER; version names are parsed from
49git tags using `git describe`.
50
51### Testing
52
53Mockito-Kotlin's test suite is located in a separate `tests` module,
54to allow running the tests using several Kotlin versions whilst still
55keeping the base module at a recent version.
56
57Testing thus must be done in two stages: one to build the base artifact
58to test against, and the actual execution of the tests against the
59built artifact:
60
61 - `./gradlew assemble` builds the base artifact
62 - `./gradlew test` runs the tests against the built artifact.
63
64Usually it is enough to test only using the default Kotlin versions;
65CI will test against multiple versions.
66If you want to test using a different Kotlin version locally, set
67an environment variable `KOTLIN_VERSION` and run the tests.
68
69### Acknowledgements
70
71`mockito-kotlin` was created and developed by [nhaarman@](https://github.com/nhaarman) after which the repository was integrated into the official Mockito GitHub organization.
72We would like to thank Niek for the original idea and extensive work plus support that went into `mockito-kotlin`.
73