https://kotlinlang.org logo
Title
k

katien

01/19/2018, 8:39 PM
it's part of kotlintest
p

poohbar

01/19/2018, 8:41 PM
sorry that i dont know exactly how to help you but i went through similar cycle and ended up using Kluent and Mockk instead of kotlin test and mockito-kotlin. https://github.com/oleksiyp/mockk mockito-kotlin is buggy and the author seems uninterested in fixing bugs
what I like about mockk is that both verification and stubbing has exactly the same syntax so there is no schizophrenia like in mockito where for one the call must be after the parenthesees and for the other it has to be inside
🙂 1
class MyTest {
    val dependency: ConcreteDependency = mockk()
    val service = ServiceUnderTest(dependency)

    @Test
    fun `should test something`() {
        every { dependency.foo(any()) } returns "some result"

        val result = service.methodUnderTest("param")

        verify { dependency.bar() }
        result shouldEqual "some result"
    }
}
k

katien

01/19/2018, 8:42 PM
I have heard good things about mockk
I'll have to check that one out
p

poohbar

01/19/2018, 8:43 PM
yeah it has no trouble with properties nor with old java code
only difference is that it is "strict" by default which means by default it won't return "null" values for calls, you have to stub everything that is called.. but in my case it actually lead to cleaner tests. YMMV