A Lesson by Craig Russell
In this lesson, we’ll explain how the
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
- 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.
Code for the Lesson
Pro members: Log in to view the code for this lesson!
Lessons in this course
- Mockito – Introduction and Integration
- Writing Your First Unit Test with Mockito
- Mockito – Writing Testable Code
- Mockito – What Makes a Good Unit Test
- Mockito – Test Doubles
- Mockito – Configuring Stubs
- Mockito – Stubs and their Default Return Values
- Mockito String Matchers – anyString()
- Mockito: Stubs – Matching on any parameters of a given type
- Mockito – Introduction to Mocks
- Mockito – Verifying a Method Was Never Called
- Mockito – Verifying a Method Was Called An Exact Number of Times
- Mockito – Verifying That a Method was Called a Minimum or Maximum Number of Times