Mockito
Mockito is a mocking framework with a clean and simple API. Tests produced with Mockito are readable, easy-to-write, and intuitive. It contains three major static methods:
mock()
: This is used to create mocks. Optionally, we can specify how those mocks behave withwhen()
andgiven()
.spy()
: This can be used for partial mocking. Spied objects invoke real methods unless we specify otherwise. As whichmock()
, behavior can be set for every public or protected method (excluding static). The major difference is thatmock()
creates a fake of the whole object, whilespy()
uses the real object.verify()
: This is used to check whether methods were called with given arguments. It is a form of assert.
We'll go deeper into Mockito once we start coding ...
Get Test-Driven Java Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.