Skip to content

Matchers are not working for suspend functions #269

@kostya-misura

Description

@kostya-misura

It 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions