Mockito is a mocking framework. It is a Java-based library used to create simple and basic test APIs for performing unit testing of Java applications. It can also be used with other frameworks such as JUnit and TestNG.
The framework allows the creation of test double objects (mock objects) in automated unit tests for the purpose of test-driven development (TDD) or behavior-driven development (BDD).
Mockito allows developers to verify the behavior of the system under test (SUT) without establishing expectations beforehand.One of the criticisms of mock objects is that there is a tight coupling of the test code to the system under test.
Benefits of Mockito:
- No Handwriting − No need to write mock objects on your own.
- Refactoring Safe − Renaming interface method names or reordering parameters will not break the test code as Mocks are created at runtime.
- Return value support − Supports return values.
- Exception support − Supports exceptions.
- Order check support − Supports check on order of method calls.
- Annotation support − Supports creating mocks using annotation.