Mockito Articles
3 articles about Mockito. Explore Spring Boot implementation, design, and operations across related topics.
-
@MockBean Deprecated in Spring Boot 3.4 - Migrating to @MockitoBean and @MockitoSpyBean and How to Use Them
@MockBean/@SpyBean are deprecated in Spring Boot 3.4. This guide explains the correct imports for their replacements @MockitoBean and @MockitoSpyBean, the package relocation, differences from the old API, and step-by-step procedures for migrating existing tests in bulk, with practical examples.
-
How to Write Controller Unit Tests with MockMvc in Spring Boot - Introduction to @WebMvcTest
Achieve fast, DB-free, copy-paste-ready Controller unit tests with @WebMvcTest and MockMvc. Explains how to mock Services with @MockBean, validate JSON with jsonPath, handle validation errors (400), and integrate Security (@WithMockUser) with practical examples.
-
Writing Tests in Spring Boot - Introduction to Unit Testing with JUnit and Mockito
Learn how to write Spring Boot unit tests with JUnit 5 and Mockito, explained step by step for the Service layer (@Mock/@InjectMocks) and Controller layer (@WebMvcTest/@MockBean/MockMvc). Master the Given-When-Then pattern, success/failure cases, and assertThrows through concrete code examples.