liveBook · Manning

@MockitoBean

@MockitoBean is a Spring testing annotation that registers a Mockito mock as a bean in the test application context, adding or replacing a matching bean.

How 2 Manning books explain it

Spring Start Here, Second Edition

A Spring Test annotation that registers a Mockito mock in the test application context, replacing an existing bean when one matches.

How it is used
Controls selected dependencies while testing Spring-managed services and web endpoints.
How deep it goes
Demonstrates declaration, injection, stubbing and verification in integration tests, without detailing bean-selection rules.
Examples
Uses a transfer service with a mocked account repository and a controller test that sends a transfer request.
What you can do after
Applies it via Spring Test and Mockito to control a dependency in an integration test.

Read how Spring Start Here, Second Edition explains @MockitoBean →

Testing Spring Boot Applications

@MockitoBean is a Spring testing annotation that registers a Mockito mock as a bean, adding or replacing a matching bean in the application context.

How it is used
Replaces or supplies application-context beans with Mockito mocks during Spring Boot tests.
How deep it goes
Explains annotation-driven replacement, named beans, default values, and stubbing, but does not detail Mockito internals.
Examples
Uses weather-service stubbing, named widget dependencies, and MockMvc requests against a full application context.
What you can do after
Apply it via Spring Boot Tests and Mockito to isolate dependencies, start the context, and verify application behavior.

Read how Testing Spring Boot Applications explains @MockitoBean →

What to know first

Related concepts

Questions about @MockitoBean

What is @MockitoBean?

@MockitoBean is a Spring testing annotation that registers a Mockito mock as a bean in the test application context, adding or replacing a matching bean.

Which Manning books explain @MockitoBean?

Spring Start Here, Second Edition and Testing Spring Boot Applications.

What should I know before learning @MockitoBean?

Manning books that teach @MockitoBean usually introduce mock bean and mocking first.

What is the difference between @MockitoBean and mock bean?

@MockitoBean is a Spring testing annotation that registers a Mockito mock as a bean in the test application context, adding or replacing a matching bean. @MockBean is a Spring Boot testing annotation that registers a Mockito mock as a bean in the application context, replacing a matching bean when present.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.