liveBook · Manning

Mockito

As explained in Testing Spring Boot Applications

Mockito is a Java mocking framework for creating configurable test doubles and verifying interactions with them.

Mockito is a Java mocking framework for creating configurable fake objects with the same APIs as production classes. It helps isolate tests from complex business logic and external dependencies such as databases, remote services, and APIs. section 1.1

Mockito supports two complementary forms of test-double configuration:

  • Stub behavior, such as making widgetService.count() return 5. section 1.1
  • Verify interactions, such as confirming that emailService.sendEmail() was called once with a specified address. section 1.1
  • Use Mockito imperatively in tests, including tests that do not involve Spring. section 1.1

How Testing Spring Boot Applications covers it

How deep it goes
Defines configurable fakes, stubbing, and verification, but does not detail Mockito APIs or implementation internals.
Examples
Uses widgetService.count() returning 5 and verifies one emailService.sendEmail() call with user@example.com.
What you can do after
Apply via Mockito by replacing dependencies, defining return values, and verifying calls in isolated tests.
How it connects
Connects mocking with test doubles, dependency isolation, databases, remote services, APIs, and assertions.

Also explained in

Compare how 4 books explain Mockito →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.