Sign in Go Pro

Mockito

Verifying That a Method was Called a Minimum or Maximum Number of Times

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next

Previous

About

#Mockito Mocks In this lesson, we'll explain how the `atLeast()` and `atMost()` verification modes work. We'll show how they can be used to verify that a method was called _at least_ a certain number of times or _at most_ a certain of times. Additionally, we'll demonstrate how to combine them both together to verify a method was called a number of times within a given range. #Summary of Content - The default implementation of `Mockito.verify()` - Customising the verification using Verification Modes - Overloaded method for `Mockito.verify()` which accepts a way of specifying that a method should never be called - How to use the `atLeast()` verification mode to verify a method was called a minimum number of times - How to use the `atMost()` verification mode to verify a method was called a maximum number of times - How to combine both to verify a method was called at least a minimum number of times, while also ensuring it was called no more than a given maximum number.

Lessons in Mockito