aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 871611e81bc23d7cddafc61dfd836b68cddee51c (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
# Mockito-Kotlin
[ ![Download](https://maven-badges.herokuapp.com/maven-central/com.nhaarman.mockitokotlin2/mockito-kotlin/badge.svg) ](https://maven-badges.herokuapp.com/maven-central/com.nhaarman.mockitokotlin2/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 "com.nhaarman.mockitokotlin2: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/nhaarman/mockito-kotlin/wiki).