This article is all about the possibilities of mocking that the Mockito package provides. We’ll look into setting up mocks, verifying the calls, and pitfalls to avoid.
I recently published an article about mocking in unit tests with the Mockito package in Flutter apps.
This follow-up article is a cheat sheet for you to quickly find an example of how to use the package. I also updated the GitHub repository of the original post and it now contains the cheat sheet as a working test class.
✅ Always use
thenAnswer(), never use
thenReturn() ▶ Explanation
✅ If you verify a mock, the invocation counter is reset!
✅ If there are multiple matching setups, the last setup wins!
You can find the source code on GitHub.