A Lesson by Craig Russell
In this lesson, we’ll explain how to verify the parameters which are passed to mock objects.
We’ll explain how Argument Captors work and how you can use them to ensure that not only is your mock method being called, but that it is being called with the correct parameter.
Summary of Content
- Showing an example where we need to not only verify that a mock method was called, but we also need interrogate the parameter passed to a mock method
- Explanation of what an Argument Captor is
- How to create an Argument Captor, using the
- How to retrieve the object that was captured by the argument captor, using the
- Showing a test passing which successfully verifies the parameter passed to a mock object.
Other Relevant Links:
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
- Mockito – Mocking and Stubbing Final Classes
- Mockito – Argument Captors