doReturn

infix fun <T> OngoingStubbing<T>.doReturn(value: T): OngoingStubbing<T>

Sets a value to be returned when the stubbed method/function is being called. E.g:

    whenever { mock.someMethod() } doReturn 10

This function is an alias for Mockito's OngoingStubbing.thenReturn.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

value

return value for the method/function invocation.


fun <T> OngoingStubbing<T>.doReturn(value: T, vararg values: T): OngoingStubbing<T>

Sets values to be returned when the stubbed method/function is being called consecutively. E.g:

    whenever { mock.someMethod() }.doReturn(10, 20)

You can specify values to be returned on consecutive invocations. In that case the last value determines the behavior of further consecutive invocations.

This function is an alias for Mockito's OngoingStubbing.thenReturn.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

value

return value for the first method/function invocation.

values

return values for the next method/function invocations.


fun doReturn(value: Any?): Stubber

Sets a value to be returned, to be applied in reverse stubbing.

Example:

    doReturn(10).whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doReturn.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

value

return value for the method/function invocation.


fun doReturn(value: Any?, vararg values: Any?): Stubber

Sets values to be returned on consecutive invocations, to be applied in reverse stubbing.

Example:

    doReturn(10, 20).whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doReturn.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

value

return value for the first method/function invocation.

values

return values for the next method/function invocations.