Mockito in a nutshell

As introduced in Chapter 1, Retrospective on Software Quality and Java Testing, there are different levels of software testing, such as unit, integration, system, or acceptance. Regarding unit tests, they should be executed in isolation for a single piece of software, for example, an individual class. The objective in this level of tests is to verify the functionality of the unit and not of its dependencies.

In other words, we want to test what is known as the System Under Test (SUT) but not its Depended-On Components (DOCs). To achieve this isolation, we use typically test doubles to replace these DOCs. Mock objects are a kind of test double, which are programmed with expectations about the real DOC.

In few words, Mockito ...

Get Mastering Software Testing with JUnit 5 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.