kotlinmockkmockk-verify

Verify exact number of invocations within verifyOrder


I want to verify that a number of functions were called in a specific order, but one of the functions gets called N times:

verifyOrder {
    myMockObject.func1()
    (exactly = 10) myMockObject.func2()
    myMockObject.func3()
}

How do I specify the "exactly = 10" above?


Solution

  • That is not possible. Your best option would be verifySequence, which verifies that the calls happened in a specified sequence.

    verifySequence {
       myMockObject.func1()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func2()
       myMockObject.func3()
    }
    

    It is not pretty, but to my knowledge, you have no better alternative.