Reputation: 8573
My understanding is that to use doReturn()
with mockito-kotlin is that I must call it from within a
val mockObj = mock<TheClass> {
on { method } doReturn something
}
how can I specify that this must use CALLS_REAL_METHODS
?
or can I use doReturn()
in some other way with val mockObj : TheClass = mock(Mockito.CALLS_REAL_METHODS)
instead?
just to clarify - this is a doReturn()
(not when/whenever
) question
Upvotes: 2
Views: 1572
Reputation: 100378
Since Mockito-Kotlin 1.2.0 mock()
takes optional parameters:
val mockObj : TheClass = mock(defaultAnswer = Mockito.CALLS_REAL_METHODS)
You can use the stubbing mechanism to then again override this default behavior for individual methods:
val mockObj = mock<TheClass>(defaultAnswer = Mockito.CALLS_REAL_METHODS) {
on { method() } doReturn something
}
Upvotes: 3