aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: abac3de0e5f92e9b5fdb8c0d84afef438b6a1b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Mockito-Kotlin
[ ![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)

A small library that provides helper functions to work with [Mockito](https://github.com/mockito/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:

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

## Example

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

```kotlin
@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](https://github.com/mockito/mockito-kotlin/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@](https://github.com/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`.