https://kotlinlang.org logo
#coroutines
Title
# coroutines
f

fstn

12/02/2017, 7:30 AM
Hi guys, how can I mock suspend function? For example, I would like to mock:
Copy code
val mockContextManager = Mockito.mock(ContextManager::class.java)
        Mockito.`when`(mockContextManager.get(1)).thenReturn(2)
where get is a suspend function
e

elizarov

12/02/2017, 7:33 AM
Use the latest version of Mockito and wrap the
Mockito.mock
invocation into
runBlocking { ... }
f

fstn

12/02/2017, 7:42 AM
thanks @elizarov, like that:
Copy code
runBlocking { Mockito.`when`(mockContextManager.get("1") ).thenReturn(mockResultForUser1) 
}
It doesn’t work mockito execute original method
4 Views