October 2019
Intermediate to advanced
434 pages
11h 54m
English
Mockito-Kotlin is an interesting example of a testing library that makes use of Kotlin features to provide a custom testing DSL that makes mocking and testing feel very fluent and readable.
In the following code snippet, you can see an example of using Mockito-Kotlin to mock the behavior of the GreetingProvider class:
@Testfun `test with mockito-kotlin`() { val mockGreeter = mock<SimpleGreeter> { on { getGreeting() } doReturn "Hey there!" on { getMessage() } doReturn "You're great!" }}
Notice that this test code is making heavy use of lambdas and higher-order functions.
The mock() function is passed a lambda within which that mocked object can have its behavior configured. This configuration becomes very human readable when ...
Read now
Unlock full access