commit | 081d2cb856b590f6699ab1010c153aff89ceed82 | [log] [tgz] |
---|---|---|
author | Jon Travis <jtravis@p00p.org> | Wed Aug 22 14:31:08 2018 -0700 |
committer | Jon Travis <jtravis@p00p.org> | Wed Aug 22 14:31:08 2018 -0700 |
tree | dfcb6821f6fd9757367aad85ee21a78ce630fcd9 | |
parent | 87059d8f1c9bbce6564fc215174fdf89b1099ec9 [diff] |
Inline `whenever` to let Mockito's UnfinishedStubbing messages work When Mockito detects unfinished stubbing, it will spit out an error containing: ``` Unfinished stubbing detected here: -> at com.nhaarman.mockitokotlin2.OngoingStubbingKt.whenever(OngoingStubbing.kt:42) ``` This is not useful in helping users track down unfinished stubbing. Instead, we inline `whenever` to make it read as: ``` Unfinished stubbing detected here: -> at com.me.MyTest.testMyThing(MyTest.kt:785) ```
A small library that provides helper functions to work with Mockito in Kotlin.
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:
testCompile "com.nhaarman.mockitokotlin2:mockito-kotlin:x.x.x"
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.