Matchers are not working for suspend functions
See original GitHub issueIt seems that if you try to use “matchers” (any, eq, etc.) on suspend function mockito fails with “InvalidUseOfMatchersException”.
following test
@Test
fun otherTest() {
val foo: Foo = mock {
on { runBlocking { bar(any()) } } doReturn ("message")
}
Mockito.validateMockitoUsage()
}
with following interface definition
interface Foo {
suspend fun bar(arg: String): String
}
produces following error
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at org.app.Tests$otherTest$i$1$1$1.doResume(Tests.kt:76)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:19
Top Results From Across the Web
Matchers are not working for suspend functions #269 - GitHub
It seems that if you try to use "matchers" (any, eq, etc.) on suspend function mockito fails with "InvalidUseOfMatchersException". following ...
Read more >Verify suspend function with Matchers.anyObject()
MyTest$testFunction$1.invokeSuspend(MyTest.kt:66) This exception may occur if matchers are combined with raw values: //incorrect: someMethod ...
Read more >Verifying suspending functions with Mockito (or alternatives)
I've run into trouble using Mockito to verify invocations of suspending functions. This appears to be related to how suspending functions ...
Read more >Suspending functions should not be called on a different ...
Kotlin static code analysis: Suspending functions should not be called on a different dispatcher.
Read more >Coroutines and suspend functions | Mocking | MockK Guidebook
Coroutines and suspend functions #. As MockK uses function literals to create stubs, small changes are needed to stub suspend functions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
same problem as @lborisevich-clgx . high order functions doesn’t seem to work:
but works with zero parameters:
I had to set my dependencies as below in my gradle file for the matchers to work within a suspend.